Skip to content

Commit

Permalink
refactor: object accessor better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Oct 15, 2023
1 parent 41e08a7 commit 161a760
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/beize_vm/lib/vm/interpreter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,25 @@ class BeizeInterpreter {

case BeizeOpCodes.opGetProperty:
final BeizeValue name = stack.pop();
final BeizePrimitiveObjectValue obj = stack.pop();
final BeizeValue obj = stack.pop();
if (obj is! BeizePrimitiveObjectValue) {
return handleInvalidMemberAccess(
'Cannot use member accessor on "${obj.kind.code}"',
);
}
final BeizeValue value = obj.get(name);
stack.push(value);
break;

case BeizeOpCodes.opSetProperty:
final BeizeValue value = stack.pop();
final BeizeValue name = stack.pop();
final BeizePrimitiveObjectValue obj = stack.pop();
final BeizeValue obj = stack.pop();
if (obj is! BeizePrimitiveObjectValue) {
return handleInvalidMemberAccess(
'Cannot do member assign on "${obj.kind.code}"',
);
}
obj.set(name, value);
stack.push(value);
break;
Expand Down Expand Up @@ -516,6 +526,9 @@ class BeizeInterpreter {
return handleException(err);
}

BeizeInterpreterResult handleInvalidMemberAccess(final String message) =>
handleCustomException('InvalidMemberAccess', message);

BeizeInterpreterResult handleInvalidUnary(final String message) =>
handleCustomException('InvalidUnaryOperation', message);

Expand Down

0 comments on commit 161a760

Please sign in to comment.