From da7ddaa7dedc47c33d444a3a432113a7d90b7aeb Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Thu, 1 Dec 2022 07:32:13 +0100 Subject: [PATCH] make setFunctionProtoAndParent context aware, deprecate the old versions cleanup promise because the setup is now correct done by the ctor --- .../mozilla/javascript/FunctionObject.java | 2 +- .../mozilla/javascript/LambdaFunction.java | 4 +-- src/org/mozilla/javascript/NativePromise.java | 5 ---- src/org/mozilla/javascript/ScriptRuntime.java | 25 ++++++++++++++----- .../javascript/regexp/NativeRegExp.java | 2 +- testsrc/test262.properties | 3 +-- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/org/mozilla/javascript/FunctionObject.java b/src/org/mozilla/javascript/FunctionObject.java index 0773ca2442..03a9531c17 100644 --- a/src/org/mozilla/javascript/FunctionObject.java +++ b/src/org/mozilla/javascript/FunctionObject.java @@ -288,7 +288,7 @@ public void addAsConstructor(Scriptable scope, Scriptable prototype) { } void initAsConstructor(Scriptable scope, Scriptable prototype) { - ScriptRuntime.setFunctionProtoAndParent(this, scope); + ScriptRuntime.setFunctionProtoAndParent(this, Context.getCurrentContext(), scope); setImmunePrototypeProperty(prototype); prototype.setParentScope(this); diff --git a/src/org/mozilla/javascript/LambdaFunction.java b/src/org/mozilla/javascript/LambdaFunction.java index d27e54f2b8..a736c797a5 100644 --- a/src/org/mozilla/javascript/LambdaFunction.java +++ b/src/org/mozilla/javascript/LambdaFunction.java @@ -34,7 +34,7 @@ public LambdaFunction(Scriptable scope, String name, int length, Callable target this.target = target; this.name = name; this.length = length; - ScriptRuntime.setFunctionProtoAndParent(this, scope); + ScriptRuntime.setFunctionProtoAndParent(this, Context.getCurrentContext(), scope); setupDefaultPrototype(); } @@ -43,7 +43,7 @@ public LambdaFunction(Scriptable scope, int length, Callable target) { this.target = target; this.length = length; this.name = ""; - ScriptRuntime.setFunctionProtoAndParent(this, scope); + ScriptRuntime.setFunctionProtoAndParent(this, Context.getCurrentContext(), scope); } @Override diff --git a/src/org/mozilla/javascript/NativePromise.java b/src/org/mozilla/javascript/NativePromise.java index e92260c8d6..ccd0297a67 100644 --- a/src/org/mozilla/javascript/NativePromise.java +++ b/src/org/mozilla/javascript/NativePromise.java @@ -35,7 +35,6 @@ public static void init(Context cx, Scriptable scope, boolean sealed) { 1, LambdaConstructor.CONSTRUCTOR_NEW, NativePromise::constructor); - constructor.setStandardPropertyAttributes(DONTENUM | READONLY); constructor.setPrototypePropertyAttributes(DONTENUM | READONLY | PERMANENT); constructor.defineConstructorMethod( @@ -541,7 +540,6 @@ private static class ResolvingFunctions { scope, promise, (args.length > 0 ? args[0] : Undefined.instance))); - resolve.setStandardPropertyAttributes(DONTENUM | READONLY); reject = new LambdaFunction( topScope, @@ -552,7 +550,6 @@ private static class ResolvingFunctions { scope, promise, (args.length > 0 ? args[0] : Undefined.instance))); - reject.setStandardPropertyAttributes(DONTENUM | READONLY); } private Object reject(Context cx, Scriptable scope, NativePromise promise, Object reason) { @@ -664,7 +661,6 @@ private static class Capability { 2, (Context cx, Scriptable scope, Scriptable thisObj, Object[] args) -> executor(args)); - executorFunc.setStandardPropertyAttributes(DONTENUM | READONLY); promise = promiseConstructor.construct(topCx, topScope, new Object[] {executorFunc}); @@ -777,7 +773,6 @@ Object resolve(Context topCx, Scriptable topScope) { } return eltResolver.resolve(cx, scope, value, this); }); - resolveFunc.setStandardPropertyAttributes(DONTENUM | READONLY); Callable rejectFunc = capability.reject; if (!failFast) { diff --git a/src/org/mozilla/javascript/ScriptRuntime.java b/src/org/mozilla/javascript/ScriptRuntime.java index c34e22a4c5..75eefebe9f 100644 --- a/src/org/mozilla/javascript/ScriptRuntime.java +++ b/src/org/mozilla/javascript/ScriptRuntime.java @@ -4249,23 +4249,36 @@ public static Scriptable leaveDotQuery(Scriptable scope) { return nw.getParentScope(); } + /** + * @deprecated Use {@link #setFunctionProtoAndParent(BaseFunction, Context, Scriptable)} instead + */ + @Deprecated public static void setFunctionProtoAndParent(BaseFunction fn, Scriptable scope) { - setFunctionProtoAndParent(fn, scope, false); + setFunctionProtoAndParent(fn, Context.getCurrentContext(), scope, false); + } + + public static void setFunctionProtoAndParent(BaseFunction fn, Context cx, Scriptable scope) { + setFunctionProtoAndParent(fn, cx, scope, false); } + /** + * @deprecated Use {@link #setFunctionProtoAndParent(BaseFunction, Context, Scriptable, + * boolean)} instead + */ + @Deprecated public static void setFunctionProtoAndParent( BaseFunction fn, Scriptable scope, boolean es6GeneratorFunction) { + setFunctionProtoAndParent(fn, Context.getCurrentContext(), scope, es6GeneratorFunction); + } + + public static void setFunctionProtoAndParent( + BaseFunction fn, Context cx, Scriptable scope, boolean es6GeneratorFunction) { fn.setParentScope(scope); if (es6GeneratorFunction) { fn.setPrototype(ScriptableObject.getGeneratorFunctionPrototype(scope)); } else { fn.setPrototype(ScriptableObject.getFunctionPrototype(scope)); } - } - - public static void setFunctionProtoAndParent( - BaseFunction fn, Context cx, Scriptable scope, boolean es6GeneratorFunction) { - setFunctionProtoAndParent(fn, scope, es6GeneratorFunction); if (cx != null && cx.getLanguageVersion() >= Context.VERSION_ES6) { fn.setStandardPropertyAttributes(ScriptableObject.READONLY | ScriptableObject.DONTENUM); diff --git a/src/org/mozilla/javascript/regexp/NativeRegExp.java b/src/org/mozilla/javascript/regexp/NativeRegExp.java index 1d73c6baab..a6dd8e7c3c 100644 --- a/src/org/mozilla/javascript/regexp/NativeRegExp.java +++ b/src/org/mozilla/javascript/regexp/NativeRegExp.java @@ -122,7 +122,7 @@ public static void init(Context cx, Scriptable scope, boolean sealed) { // RegExp.prototype.constructor is the builtin RegExp constructor." proto.defineProperty("constructor", ctor, ScriptableObject.DONTENUM); - ScriptRuntime.setFunctionProtoAndParent(ctor, scope); + ScriptRuntime.setFunctionProtoAndParent(ctor, cx, scope); ctor.setImmunePrototypeProperty(proto); diff --git a/testsrc/test262.properties b/testsrc/test262.properties index 96b97e3ea7..2b6d0b2476 100644 --- a/testsrc/test262.properties +++ b/testsrc/test262.properties @@ -3542,8 +3542,7 @@ language/expressions/conditional 3/22 (13.64%) tco-cond.js {unsupported: [tail-call-optimization]} tco-pos.js {unsupported: [tail-call-optimization]} -language/expressions/delete 4/61 (6.56%) - 11.4.1-5-a-28-s.js strict +language/expressions/delete 3/61 (4.92%) identifier-strict.js strict super-property.js {unsupported: [class]} super-property-method.js {unsupported: [class]}