Skip to content

Commit

Permalink
fix Cannot access null value from map
Browse files Browse the repository at this point in the history
  • Loading branch information
apps-auth committed Oct 10, 2024
1 parent b06ed0d commit 72b32b0
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 7 deletions.
31 changes: 24 additions & 7 deletions lib/src/eval/runtime/ops/objects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,23 @@ class InvokeDynamic implements EvcOp {
runtime._prOffset = object.offset;
return;
}
final method = ((object as $Instance).$getProperty(runtime, _method)
as EvalFunction);
try {
runtime.returnValue = method.call(runtime, object, runtime.args.cast());
} catch (e) {
runtime.$throw(e);

if (object == null) {
object = $Null();
}

if (object is $Instance) {
final method = (object.$getProperty(runtime, _method) as EvalFunction);
try {
runtime.returnValue =
method.call(runtime, object, runtime.args.cast());
} catch (e) {
runtime.$throw(e);
}
} else {
runtime.returnValue = $null();
}

runtime.args = [];
return;
}
Expand Down Expand Up @@ -156,7 +166,14 @@ class CheckEq implements EvcOp {
return;
}

runtime.returnValue = v1 == v2;
if (v2 is $Value && v1 is! $Value) {
runtime.returnValue = v2.$value == v1;
} else if (v1 is $Value && v2 is! $Value) {
runtime.returnValue = v1.$value == v2;
} else {
runtime.returnValue = v1 == v2;
}

return;
}
}
Expand Down
68 changes: 68 additions & 0 deletions lib/src/eval/shared/stdlib/core/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,71 @@ class $String implements $Instance {
@override
int get hashCode => $value.hashCode;
}

/// dart_eval [$Instance] representation of a [Null]
class $Null implements $Instance {
$Null() : _superclass = $Object(_Null());

static const $declaration = BridgeClassDef(
BridgeClassType(BridgeTypeRef(CoreTypes.nullType), isAbstract: true),
constructors: {},
methods: {
// Other Null methods defined in builtins.dart
},
wrap: true);

final $Instance _superclass;

@override
$Value? $getProperty(Runtime runtime, String identifier) {
try {
return _superclass.$getProperty(runtime, identifier);
} catch (e) {
return $Function((
Runtime runtime,
$Value? target,
List<$Value?> args,
) {
return $null();
});
}
}

@override
void $setProperty(Runtime runtime, String identifier, $Value value) {}

@override
_Null get $reified => $value;

@override
bool operator ==(Object other) {
return identical(this, other) ||
other is $Null &&
runtimeType == other.runtimeType &&
$value == other.$value;
}

@override
int get hashCode => $value.hashCode;

@override
String toString() {
return '\$${$value}';
}

@override
int $getRuntimeType(Runtime runtime) =>
runtime.lookupType(CoreTypes.nullType);

@override
get $value => _Null();
}

@pragma("vm:entry-point")
class _Null extends Object {
String toString() => "null";

dynamic noSuchMethod(Invocation invocation) {
print("_Null.noSuchMethod(): $invocation");
}
}

0 comments on commit 72b32b0

Please sign in to comment.