@@ -181,7 +181,7 @@ private static Scriptable construct(
181
181
if (result != null ) {
182
182
result .setPrototype ((Scriptable ) newTargetPrototype );
183
183
184
- Object val = ctorBaseFunction .call (cx , scope , result , args );
184
+ Object val = ctorBaseFunction .call (cx , scope , result , callArgs );
185
185
if (val instanceof Scriptable ) {
186
186
return (Scriptable ) val ;
187
187
}
@@ -325,21 +325,35 @@ private static Object preventExtensions(
325
325
326
326
private static Object set (Context cx , Scriptable scope , Scriptable thisObj , Object [] args ) {
327
327
ScriptableObject target = checkTarget (args );
328
+ if (args .length < 2 ) {
329
+ return true ;
330
+ }
328
331
329
- if (args .length > 1 ) {
330
- if (ScriptRuntime .isSymbol (args [1 ])) {
331
- target .put ((Symbol ) args [1 ], target , args [2 ]);
332
- return true ;
333
- }
334
- if (args [1 ] instanceof Double ) {
335
- target .put (ScriptRuntime .toIndex (args [1 ]), target , args [2 ]);
336
- return true ;
332
+ ScriptableObject receiver = args .length > 3 ? ScriptableObject .ensureScriptableObject (args [3 ]) : target ;
333
+ if (receiver != target ) {
334
+ ScriptableObject descriptor = target .getOwnPropertyDescriptor (cx , args [1 ]);
335
+ if (descriptor != null ) {
336
+ Object setter = descriptor .get ("set" );
337
+ if (setter != null && setter != NOT_FOUND ) {
338
+ ((Function ) setter ).call (cx , scope , receiver , new Object [] {args [2 ]});
339
+ return true ;
340
+ }
341
+
342
+ if (descriptor .get ("configurable" ) == Boolean .FALSE ) {
343
+ return false ;
344
+ }
337
345
}
346
+ }
338
347
339
- target .put (ScriptRuntime .toString (args [1 ]), target , args [2 ]);
340
- return true ;
348
+ if (ScriptRuntime .isSymbol (args [1 ])) {
349
+ receiver .put ((Symbol ) args [1 ], receiver , args [2 ]);
350
+ } else if (args [1 ] instanceof Double ) {
351
+ receiver .put (ScriptRuntime .toIndex (args [1 ]), receiver , args [2 ]);
352
+ } else {
353
+ receiver .put (ScriptRuntime .toString (args [1 ]), receiver , args [2 ]);
341
354
}
342
- return false ;
355
+
356
+ return true ;
343
357
}
344
358
345
359
private static Object setPrototypeOf (
0 commit comments