Skip to content

Commit 8ac9a55

Browse files
authored
feat(engine): GetNewTarget (#595)
1 parent cd57c9d commit 8ac9a55

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

nova_vm/src/engine/bytecode/bytecode_compiler.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,8 +1414,12 @@ impl CompileEvaluation for ast::ImportExpression<'_> {
14141414
}
14151415

14161416
impl CompileEvaluation for ast::MetaProperty<'_> {
1417-
fn compile(&self, _ctx: &mut CompileContext) {
1418-
todo!()
1417+
fn compile(&self, ctx: &mut CompileContext) {
1418+
if self.meta.name == "new" && self.property.name == "target" {
1419+
ctx.add_instruction(Instruction::GetNewTarget);
1420+
} else {
1421+
todo!();
1422+
}
14191423
}
14201424
}
14211425

nova_vm/src/engine/bytecode/instructions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ pub enum Instruction {
7575
///
7676
/// This instruction has the number of argument values that need to be
7777
/// popped from the stack (last to first) as an argument, the value on the
78-
/// stack afterwards is the constructor to
79-
/// call.
78+
/// stack afterwards is the constructor to call.
8079
EvaluateNew,
8180
/// Store SuperCall() as the result value.
8281
///
@@ -361,6 +360,8 @@ pub enum Instruction {
361360
IteratorClose,
362361
/// Perform AsyncCloseIterator on the current iterator
363362
AsyncIteratorClose,
363+
/// Store GetNewTarget() as the result value.
364+
GetNewTarget,
364365
}
365366

366367
impl Instruction {

nova_vm/src/engine/bytecode/vm.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,6 +2386,16 @@ impl<'a> Vm {
23862386
.unbind(),
23872387
);
23882388
}
2389+
Instruction::GetNewTarget => {
2390+
// 1. Let envRec be GetThisEnvironment().
2391+
let env_rec = get_this_environment(agent);
2392+
// 2. Assert: envRec has a [[NewTarget]] field.
2393+
let EnvironmentIndex::Function(env_rec) = env_rec else {
2394+
unreachable!()
2395+
};
2396+
// 3. Return envRec.[[NewTarget]].
2397+
vm.result = Some(agent[env_rec].new_target.unwrap().into_value());
2398+
}
23892399
other => todo!("{other:?}"),
23902400
}
23912401

tests/expectations.json

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@
146146
"built-ins/Array/prototype/filter/15.4.4.20-9-c-i-20.js": "FAIL",
147147
"built-ins/Array/prototype/filter/15.4.4.20-9-c-iii-23.js": "CRASH",
148148
"built-ins/Array/prototype/filter/create-revoked-proxy.js": "CRASH",
149-
"built-ins/Array/prototype/flatMap/this-value-ctor-object-species-custom-ctor-poisoned-throws.js": "CRASH",
150-
"built-ins/Array/prototype/flatMap/this-value-ctor-object-species-custom-ctor.js": "CRASH",
151149
"built-ins/Array/prototype/forEach/15.4.4.18-1-12.js": "CRASH",
152150
"built-ins/Array/prototype/forEach/15.4.4.18-5-16.js": "CRASH",
153151
"built-ins/Array/prototype/forEach/15.4.4.18-7-b-16.js": "FAIL",
@@ -988,10 +986,6 @@
988986
"built-ins/Function/prototype/apply/this-not-callable-realm.js": "FAIL",
989987
"built-ins/Function/prototype/bind/get-fn-realm-recursive.js": "FAIL",
990988
"built-ins/Function/prototype/bind/get-fn-realm.js": "CRASH",
991-
"built-ins/Function/prototype/bind/instance-construct-newtarget-boundtarget-bound.js": "CRASH",
992-
"built-ins/Function/prototype/bind/instance-construct-newtarget-boundtarget.js": "CRASH",
993-
"built-ins/Function/prototype/bind/instance-construct-newtarget-self-new.js": "CRASH",
994-
"built-ins/Function/prototype/bind/instance-construct-newtarget-self-reflect.js": "CRASH",
995989
"built-ins/Function/prototype/bind/instance-length-exceeds-int32.js": "FAIL",
996990
"built-ins/Function/prototype/bind/instance-length-prop-desc.js": "CRASH",
997991
"built-ins/Function/prototype/bind/instance-length-tointeger.js": "FAIL",
@@ -10594,7 +10588,6 @@
1059410588
"language/eval-code/indirect/var-env-var-strict.js": "FAIL",
1059510589
"language/expressions/arrow-function/arrow/capturing-closure-variables-2.js": "CRASH",
1059610590
"language/expressions/arrow-function/length-dflt.js": "FAIL",
10597-
"language/expressions/arrow-function/lexical-new.target-closure-returned.js": "CRASH",
1059810591
"language/expressions/arrow-function/lexical-new.target.js": "CRASH",
1059910592
"language/expressions/arrow-function/lexical-super-property-from-within-constructor.js": "CRASH",
1060010593
"language/expressions/arrow-function/lexical-super-property.js": "CRASH",
@@ -13962,10 +13955,7 @@
1396213955
"language/expressions/new.target/value-via-fpapply.js": "CRASH",
1396313956
"language/expressions/new.target/value-via-fpcall.js": "CRASH",
1396413957
"language/expressions/new.target/value-via-member.js": "CRASH",
13965-
"language/expressions/new.target/value-via-new.js": "CRASH",
1396613958
"language/expressions/new.target/value-via-reflect-apply.js": "CRASH",
13967-
"language/expressions/new.target/value-via-reflect-construct.js": "CRASH",
13968-
"language/expressions/new.target/value-via-super-call.js": "CRASH",
1396913959
"language/expressions/new.target/value-via-super-property.js": "CRASH",
1397013960
"language/expressions/new.target/value-via-tagged-template.js": "CRASH",
1397113961
"language/expressions/object/computed-property-name-topropertykey-before-value-evaluation.js": "CRASH",
@@ -14182,7 +14172,6 @@
1418214172
"language/expressions/optional-chaining/call-expression.js": "CRASH",
1418314173
"language/expressions/optional-chaining/iteration-statement-for-await-of.js": "CRASH",
1418414174
"language/expressions/optional-chaining/member-expression.js": "CRASH",
14185-
"language/expressions/optional-chaining/new-target-optional-call.js": "CRASH",
1418614175
"language/expressions/optional-chaining/super-property-optional-call.js": "CRASH",
1418714176
"language/expressions/postfix-decrement/S11.3.2_A5_T1.js": "CRASH",
1418814177
"language/expressions/postfix-decrement/S11.3.2_A5_T2.js": "CRASH",
@@ -14212,7 +14201,6 @@
1421214201
"language/expressions/right-shift/bigint-toprimitive.js": "CRASH",
1421314202
"language/expressions/right-shift/bigint-wrapped-values.js": "CRASH",
1421414203
"language/expressions/right-shift/bigint.js": "CRASH",
14215-
"language/expressions/super/call-construct-invocation.js": "CRASH",
1421614204
"language/expressions/super/prop-dot-cls-null-proto.js": "CRASH",
1421714205
"language/expressions/super/prop-dot-cls-ref-strict.js": "CRASH",
1421814206
"language/expressions/super/prop-dot-cls-ref-this.js": "CRASH",
@@ -19578,7 +19566,6 @@
1957819566
"staging/sm/Proxy/setPrototypeOf.js": "CRASH",
1957919567
"staging/sm/Proxy/trap-null.js": "FAIL",
1958019568
"staging/sm/Reflect/apply.js": "CRASH",
19581-
"staging/sm/Reflect/construct.js": "CRASH",
1958219569
"staging/sm/Reflect/deleteProperty.js": "FAIL",
1958319570
"staging/sm/Reflect/has.js": "FAIL",
1958419571
"staging/sm/Reflect/isExtensible.js": "CRASH",
@@ -19858,10 +19845,8 @@
1985819845
"staging/sm/class/methDefn.js": "CRASH",
1985919846
"staging/sm/class/methodName.js": "CRASH",
1986019847
"staging/sm/class/methodsPrototype.js": "FAIL",
19861-
"staging/sm/class/newTargetArgumentsIntact.js": "CRASH",
1986219848
"staging/sm/class/newTargetArrow.js": "CRASH",
1986319849
"staging/sm/class/newTargetBound.js": "CRASH",
19864-
"staging/sm/class/newTargetCCW.js": "CRASH",
1986519850
"staging/sm/class/newTargetDVG.js": "CRASH",
1986619851
"staging/sm/class/newTargetDefaults.js": "CRASH",
1986719852
"staging/sm/class/newTargetDirectInvoke.js": "CRASH",
@@ -19904,7 +19889,6 @@
1990419889
"staging/sm/destructuring/order-super.js": "CRASH",
1990519890
"staging/sm/destructuring/order.js": "FAIL",
1990619891
"staging/sm/expressions/ToPropertyKey-symbols.js": "CRASH",
19907-
"staging/sm/expressions/computed-property-side-effects.js": "CRASH",
1990819892
"staging/sm/expressions/delete-name-parenthesized-early-error-strict-mode.js": "FAIL",
1990919893
"staging/sm/expressions/destructuring-array-default-class.js": "CRASH",
1991019894
"staging/sm/expressions/destructuring-array-default-simple.js": "CRASH",
@@ -20087,4 +20071,4 @@
2008720071
"staging/sm/syntax/syntax-parsed-arrow-then-directive.js": "FAIL",
2008820072
"staging/sm/types/8.12.5-01.js": "CRASH",
2008920073
"staging/source-phase-imports/import-source-source-text-module.js": "CRASH"
20090-
}
20074+
}

tests/metrics.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"results": {
3-
"crash": 12121,
4-
"fail": 7743,
5-
"pass": 26872,
3+
"crash": 12104,
4+
"fail": 7744,
5+
"pass": 26888,
66
"skip": 65,
77
"timeout": 0,
88
"unresolved": 0

0 commit comments

Comments
 (0)