Skip to content

feat(engine): GetNewTarget #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nova_vm/src/engine/bytecode/bytecode_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,8 +1414,12 @@ impl CompileEvaluation for ast::ImportExpression<'_> {
}

impl CompileEvaluation for ast::MetaProperty<'_> {
fn compile(&self, _ctx: &mut CompileContext) {
todo!()
fn compile(&self, ctx: &mut CompileContext) {
if self.meta.name == "new" && self.property.name == "target" {
ctx.add_instruction(Instruction::GetNewTarget);
} else {
todo!();
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions nova_vm/src/engine/bytecode/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ pub enum Instruction {
///
/// This instruction has the number of argument values that need to be
/// popped from the stack (last to first) as an argument, the value on the
/// stack afterwards is the constructor to
/// call.
/// stack afterwards is the constructor to call.
EvaluateNew,
/// Store SuperCall() as the result value.
///
Expand Down Expand Up @@ -361,6 +360,8 @@ pub enum Instruction {
IteratorClose,
/// Perform AsyncCloseIterator on the current iterator
AsyncIteratorClose,
/// Store GetNewTarget() as the result value.
GetNewTarget,
}

impl Instruction {
Expand Down
10 changes: 10 additions & 0 deletions nova_vm/src/engine/bytecode/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,16 @@ impl<'a> Vm {
.unbind(),
);
}
Instruction::GetNewTarget => {
// 1. Let envRec be GetThisEnvironment().
let env_rec = get_this_environment(agent);
// 2. Assert: envRec has a [[NewTarget]] field.
let EnvironmentIndex::Function(env_rec) = env_rec else {
unreachable!()
};
// 3. Return envRec.[[NewTarget]].
vm.result = Some(agent[env_rec].new_target.unwrap().into_value());
}
other => todo!("{other:?}"),
}

Expand Down
18 changes: 1 addition & 17 deletions tests/expectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@
"built-ins/Array/prototype/filter/15.4.4.20-9-c-i-20.js": "FAIL",
"built-ins/Array/prototype/filter/15.4.4.20-9-c-iii-23.js": "CRASH",
"built-ins/Array/prototype/filter/create-revoked-proxy.js": "CRASH",
"built-ins/Array/prototype/flatMap/this-value-ctor-object-species-custom-ctor-poisoned-throws.js": "CRASH",
"built-ins/Array/prototype/flatMap/this-value-ctor-object-species-custom-ctor.js": "CRASH",
"built-ins/Array/prototype/forEach/15.4.4.18-1-12.js": "CRASH",
"built-ins/Array/prototype/forEach/15.4.4.18-5-16.js": "CRASH",
"built-ins/Array/prototype/forEach/15.4.4.18-7-b-16.js": "FAIL",
Expand Down Expand Up @@ -988,10 +986,6 @@
"built-ins/Function/prototype/apply/this-not-callable-realm.js": "FAIL",
"built-ins/Function/prototype/bind/get-fn-realm-recursive.js": "FAIL",
"built-ins/Function/prototype/bind/get-fn-realm.js": "CRASH",
"built-ins/Function/prototype/bind/instance-construct-newtarget-boundtarget-bound.js": "CRASH",
"built-ins/Function/prototype/bind/instance-construct-newtarget-boundtarget.js": "CRASH",
"built-ins/Function/prototype/bind/instance-construct-newtarget-self-new.js": "CRASH",
"built-ins/Function/prototype/bind/instance-construct-newtarget-self-reflect.js": "CRASH",
"built-ins/Function/prototype/bind/instance-length-exceeds-int32.js": "FAIL",
"built-ins/Function/prototype/bind/instance-length-prop-desc.js": "CRASH",
"built-ins/Function/prototype/bind/instance-length-tointeger.js": "FAIL",
Expand Down Expand Up @@ -10594,7 +10588,6 @@
"language/eval-code/indirect/var-env-var-strict.js": "FAIL",
"language/expressions/arrow-function/arrow/capturing-closure-variables-2.js": "CRASH",
"language/expressions/arrow-function/length-dflt.js": "FAIL",
"language/expressions/arrow-function/lexical-new.target-closure-returned.js": "CRASH",
"language/expressions/arrow-function/lexical-new.target.js": "CRASH",
"language/expressions/arrow-function/lexical-super-property-from-within-constructor.js": "CRASH",
"language/expressions/arrow-function/lexical-super-property.js": "CRASH",
Expand Down Expand Up @@ -13962,10 +13955,7 @@
"language/expressions/new.target/value-via-fpapply.js": "CRASH",
"language/expressions/new.target/value-via-fpcall.js": "CRASH",
"language/expressions/new.target/value-via-member.js": "CRASH",
"language/expressions/new.target/value-via-new.js": "CRASH",
"language/expressions/new.target/value-via-reflect-apply.js": "CRASH",
"language/expressions/new.target/value-via-reflect-construct.js": "CRASH",
"language/expressions/new.target/value-via-super-call.js": "CRASH",
"language/expressions/new.target/value-via-super-property.js": "CRASH",
"language/expressions/new.target/value-via-tagged-template.js": "CRASH",
"language/expressions/object/computed-property-name-topropertykey-before-value-evaluation.js": "CRASH",
Expand Down Expand Up @@ -14182,7 +14172,6 @@
"language/expressions/optional-chaining/call-expression.js": "CRASH",
"language/expressions/optional-chaining/iteration-statement-for-await-of.js": "CRASH",
"language/expressions/optional-chaining/member-expression.js": "CRASH",
"language/expressions/optional-chaining/new-target-optional-call.js": "CRASH",
"language/expressions/optional-chaining/super-property-optional-call.js": "CRASH",
"language/expressions/postfix-decrement/S11.3.2_A5_T1.js": "CRASH",
"language/expressions/postfix-decrement/S11.3.2_A5_T2.js": "CRASH",
Expand Down Expand Up @@ -14212,7 +14201,6 @@
"language/expressions/right-shift/bigint-toprimitive.js": "CRASH",
"language/expressions/right-shift/bigint-wrapped-values.js": "CRASH",
"language/expressions/right-shift/bigint.js": "CRASH",
"language/expressions/super/call-construct-invocation.js": "CRASH",
"language/expressions/super/prop-dot-cls-null-proto.js": "CRASH",
"language/expressions/super/prop-dot-cls-ref-strict.js": "CRASH",
"language/expressions/super/prop-dot-cls-ref-this.js": "CRASH",
Expand Down Expand Up @@ -19578,7 +19566,6 @@
"staging/sm/Proxy/setPrototypeOf.js": "CRASH",
"staging/sm/Proxy/trap-null.js": "FAIL",
"staging/sm/Reflect/apply.js": "CRASH",
"staging/sm/Reflect/construct.js": "CRASH",
"staging/sm/Reflect/deleteProperty.js": "FAIL",
"staging/sm/Reflect/has.js": "FAIL",
"staging/sm/Reflect/isExtensible.js": "CRASH",
Expand Down Expand Up @@ -19858,10 +19845,8 @@
"staging/sm/class/methDefn.js": "CRASH",
"staging/sm/class/methodName.js": "CRASH",
"staging/sm/class/methodsPrototype.js": "FAIL",
"staging/sm/class/newTargetArgumentsIntact.js": "CRASH",
"staging/sm/class/newTargetArrow.js": "CRASH",
"staging/sm/class/newTargetBound.js": "CRASH",
"staging/sm/class/newTargetCCW.js": "CRASH",
"staging/sm/class/newTargetDVG.js": "CRASH",
"staging/sm/class/newTargetDefaults.js": "CRASH",
"staging/sm/class/newTargetDirectInvoke.js": "CRASH",
Expand Down Expand Up @@ -19904,7 +19889,6 @@
"staging/sm/destructuring/order-super.js": "CRASH",
"staging/sm/destructuring/order.js": "FAIL",
"staging/sm/expressions/ToPropertyKey-symbols.js": "CRASH",
"staging/sm/expressions/computed-property-side-effects.js": "CRASH",
"staging/sm/expressions/delete-name-parenthesized-early-error-strict-mode.js": "FAIL",
"staging/sm/expressions/destructuring-array-default-class.js": "CRASH",
"staging/sm/expressions/destructuring-array-default-simple.js": "CRASH",
Expand Down Expand Up @@ -20087,4 +20071,4 @@
"staging/sm/syntax/syntax-parsed-arrow-then-directive.js": "FAIL",
"staging/sm/types/8.12.5-01.js": "CRASH",
"staging/source-phase-imports/import-source-source-text-module.js": "CRASH"
}
}
6 changes: 3 additions & 3 deletions tests/metrics.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"results": {
"crash": 12121,
"fail": 7743,
"pass": 26872,
"crash": 12104,
"fail": 7744,
"pass": 26888,
"skip": 65,
"timeout": 0,
"unresolved": 0
Expand Down