You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In strict mode, ScriptableObject.putImpl(Object,int,Scriptable,Object) prematurely breaks on !isExtensible, setters don't get a chance to be called
#616
Closed
stijnkliemesch opened this issue
Nov 8, 2019
· 1 comment
public static void main(String[] cmdlineArgs) {
final Context context = ContextFactory.getGlobal().enterContext();
try {
final Script compiledScript = context.compileString(""
+ "\"use strict\";\n"
+ "var a = function(){this._x = 2;};\n"
+ "Object.defineProperty(a.prototype, \"x\", {get:(function x() {return this._x;}), set:(function x(x) {this._x = x;})});\n"
+ "Object.freeze(a.prototype);\n"
+ "var b = new a();\n"
+ "var c = b.x;\n"
+ "b.x = 1;\n"
+ "b.x+c;",
"eval", 1, null
);
ScriptableObject global = context.initSafeStandardObjects();
final Object obj
= ScriptRuntime.doTopCall(
(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) -> compiledScript.exec(context, scope),
context, global, null, new Object[]{}, true);
System.out.println(obj);
int i = 0;
} finally {
Context.exit();
}
}
Expected output is:
3.0
instead, this results in a thrown Exception
Exception in thread "main" org.mozilla.javascript.EcmaError: TypeError: Cannot add properties to this object because extensible is false. (eval#7)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4251)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4229)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:4262)
at org.mozilla.javascript.ScriptRuntime.typeError0(ScriptRuntime.java:4268)
at org.mozilla.javascript.ScriptableObject.putImpl(ScriptableObject.java:2813)
at org.mozilla.javascript.ScriptableObject.put(ScriptableObject.java:521)
at org.mozilla.javascript.IdScriptableObject.put(IdScriptableObject.java:479)
at org.mozilla.javascript.ScriptableObject.putProperty(ScriptableObject.java:2507)
at org.mozilla.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1743)
at org.mozilla.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1737)
at org.mozilla.javascript.gen.eval_1._c_script_0(eval:5)
at org.mozilla.javascript.gen.eval_1.call(eval)
at org.mozilla.javascript.gen.eval_1.exec(eval)
...
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:412)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3561)
...
The text was updated successfully, but these errors were encountered:
stijnkliemesch
changed the title
In strict mode, ScriptableObject.putImpl(Object,int,Scriptable.Object) prematurely breaks on !isExtensible, setters don't get a chance to be called
In strict mode, ScriptableObject.putImpl(Object,int,Scriptable,Object) prematurely breaks on !isExtensible, setters don't get a chance to be called
Nov 8, 2019
No longer prematurely throws a TypeError for non-extensible objects.
Affects strict mode only.
No longer prematurely throws a TypeError in ScriptableObject.putImpl(Object,int,Scriptable,Object) when instance member isExtensible is false.
Instead, now it first queries the slotmap, so that if a GetterSlot instance is returned, any present setter may be called. All other outcomes of this method should be unaffected.
Executing the following code:
Expected output is:
instead, this results in a thrown Exception
The text was updated successfully, but these errors were encountered: