Skip to content

Commit

Permalink
make setFunctionProtoAndParent context aware,
Browse files Browse the repository at this point in the history
deprecate the old versions
cleanup promise because the setup is now correct done by the ctor
  • Loading branch information
rbri committed Dec 2, 2022
1 parent cbf8333 commit da7ddaa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/org/mozilla/javascript/FunctionObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/org/mozilla/javascript/LambdaFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/org/mozilla/javascript/NativePromise.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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});

Expand Down Expand Up @@ -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) {
Expand Down
25 changes: 19 additions & 6 deletions src/org/mozilla/javascript/ScriptRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/org/mozilla/javascript/regexp/NativeRegExp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions testsrc/test262.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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]}
Expand Down

0 comments on commit da7ddaa

Please sign in to comment.