Skip to content

Commit

Permalink
Allow get [symbol] syntax in object literals
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabergia committed Dec 6, 2024
1 parent 0ef314f commit 4c7e556
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11.0
Original file line number Diff line number Diff line change
Expand Up @@ -4885,7 +4885,10 @@ public static void fillObjectLiteral(
Callable getterOrSetter = (Callable) value;
boolean isSetter = getterSetter == 1;
Integer index = id instanceof Integer ? (Integer) id : null;
String key = index == null ? ScriptRuntime.toString(id) : null;
Object key =
index != null
? null
: (id instanceof Symbol ? id : ScriptRuntime.toString(id));
so.setGetterOrSetter(key, index == null ? 0 : index, getterOrSetter, isSetter);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ public void setAttributes(Symbol key, int attributes) {

/** Implement the legacy "__defineGetter__" and "__defineSetter__" methods. */
public void setGetterOrSetter(
String name, int index, Callable getterOrSetter, boolean isSetter) {
if (name != null && index != 0) throw new IllegalArgumentException(name);
Object name, int index, Callable getterOrSetter, boolean isSetter) {
if (name != null && index != 0) throw new IllegalArgumentException(name.toString());
checkNotSealed(name, index);

AccessorSlot aSlot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ public void computedPropertyNameForGetterSetterWork() {
});
}

@Test
public void computedPropertyNameAsSymbolForGetterSetterWork() {
Utils.runWithAllOptimizationLevels(
cx -> {
cx.setLanguageVersion(Context.VERSION_ES6);
String script =
"var o = { get [Symbol.toStringTag]() { return 'foo'; }}; o.toString()";

ScriptableObject scope = cx.initStandardObjects();
Object value = cx.evaluateString(scope, script, "test", 1, null);
assertEquals("[object foo]", value);
return null;
});
}

@Test
public void yieldWorksForPropertyValues() {
Utils.runWithAllOptimizationLevels(
Expand Down
23 changes: 5 additions & 18 deletions tests/testsrc/test262.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,7 @@ built-ins/Math 51/327 (15.6%)

built-ins/NaN 0/6 (0.0%)

built-ins/NativeErrors 29/123 (23.58%)
AggregateError/errors-iterabletolist-failures.js
built-ins/NativeErrors 28/123 (22.76%)
AggregateError/is-a-constructor.js {unsupported: [Reflect.construct]}
AggregateError/newtarget-proto-custom.js {unsupported: [Reflect.construct]}
AggregateError/newtarget-proto-fallback.js
Expand Down Expand Up @@ -1063,7 +1062,7 @@ built-ins/Number 24/335 (7.16%)
S9.3.1_A3_T1_U180E.js {unsupported: [u180e]}
S9.3.1_A3_T2_U180E.js {unsupported: [u180e]}

built-ins/Object 216/3408 (6.34%)
built-ins/Object 215/3408 (6.31%)
assign/assignment-to-readonly-property-of-target-must-throw-a-typeerror-exception.js
assign/not-a-constructor.js {unsupported: [Reflect.construct]}
assign/source-own-prop-desc-missing.js {unsupported: [Proxy]}
Expand Down Expand Up @@ -1133,7 +1132,6 @@ built-ins/Object 216/3408 (6.34%)
freeze/throws-when-false.js
freeze/typedarray-backed-by-resizable-buffer.js {unsupported: [resizable-arraybuffer]}
fromEntries/not-a-constructor.js {unsupported: [Reflect.construct]}
fromEntries/uses-keys-not-iterator.js
getOwnPropertyDescriptors/not-a-constructor.js {unsupported: [Reflect.construct]}
getOwnPropertyDescriptors/observable-operations.js {unsupported: [Proxy]}
getOwnPropertyDescriptors/order-after-define-property.js {unsupported: [Reflect]}
Expand Down Expand Up @@ -1679,7 +1677,7 @@ built-ins/Promise 406/631 (64.34%)

~built-ins/Reflect

built-ins/RegExp 1152/1854 (62.14%)
built-ins/RegExp 1151/1854 (62.08%)
CharacterClassEscapes 24/24 (100.0%)
dotall 4/4 (100.0%)
escape 20/20 (100.0%)
Expand Down Expand Up @@ -1762,7 +1760,6 @@ built-ins/RegExp 1152/1854 (62.14%)
prototype/Symbol.matchAll/isregexp-this-throws.js
prototype/Symbol.matchAll/not-a-constructor.js {unsupported: [Reflect.construct]}
prototype/Symbol.matchAll/species-constructor.js
prototype/Symbol.matchAll/species-constructor-get-species-throws.js
prototype/Symbol.matchAll/this-get-flags.js
prototype/Symbol.matchAll/this-not-object-throws.js
prototype/Symbol.matchAll/this-tostring-flags.js
Expand Down Expand Up @@ -2136,7 +2133,7 @@ built-ins/SetIteratorPrototype 0/11 (0.0%)

~built-ins/SharedArrayBuffer

built-ins/String 101/1182 (8.54%)
built-ins/String 93/1182 (7.87%)
fromCharCode/not-a-constructor.js {unsupported: [Reflect.construct]}
fromCodePoint/not-a-constructor.js {unsupported: [Reflect.construct]}
prototype/charAt/not-a-constructor.js {unsupported: [Reflect.construct]}
Expand Down Expand Up @@ -2222,15 +2219,7 @@ built-ins/String 101/1182 (8.54%)
prototype/toWellFormed/not-a-constructor.js {unsupported: [Reflect.construct]}
prototype/toWellFormed/to-string-primitive.js
prototype/trimEnd/not-a-constructor.js {unsupported: [Reflect.construct]}
prototype/trimEnd/this-value-object-toprimitive-call-err.js
prototype/trimEnd/this-value-object-toprimitive-meth-priority.js
prototype/trimEnd/this-value-object-tostring-meth-priority.js
prototype/trimEnd/this-value-object-valueof-meth-priority.js
prototype/trimStart/not-a-constructor.js {unsupported: [Reflect.construct]}
prototype/trimStart/this-value-object-toprimitive-call-err.js
prototype/trimStart/this-value-object-toprimitive-meth-priority.js
prototype/trimStart/this-value-object-tostring-meth-priority.js
prototype/trimStart/this-value-object-valueof-meth-priority.js
prototype/trim/not-a-constructor.js {unsupported: [Reflect.construct]}
prototype/trim/u180e.js {unsupported: [u180e]}
prototype/valueOf/non-generic-realm.js
Expand Down Expand Up @@ -3512,13 +3501,11 @@ language/comments 9/52 (17.31%)
multi-line-asi-line-separator.js
multi-line-asi-paragraph-separator.js

language/computed-property-names 37/48 (77.08%)
language/computed-property-names 35/48 (72.92%)
class/accessor 4/4 (100.0%)
class/method 11/11 (100.0%)
class/static 14/14 (100.0%)
object/accessor/getter.js
object/accessor/getter-super.js
object/accessor/setter.js
object/accessor/setter-super.js
object/method/generator.js
object/method/super.js
Expand Down

0 comments on commit 4c7e556

Please sign in to comment.