Skip to content

Commit

Permalink
Make toStringTag writable
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Garn committed Sep 19, 2022
1 parent 312fc2c commit 8e5fe59
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ public void testToString() {
try (Context context = builder.build()) {
Value result = context.eval(JavaScriptLanguage.ID, "AsyncIterator.prototype[Symbol.toStringTag]");
Assert.assertEquals("Async Iterator", result.asString());

result = context.eval(JavaScriptLanguage.ID, "AsyncIterator.prototype[Symbol.toStringTag] = 'Changed'; AsyncIterator.prototype[Symbol.toStringTag]");
Assert.assertEquals("Changed", result.asString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ public void testToString() {
try (Context context = builder.build()) {
Value result = context.eval(JavaScriptLanguage.ID, "Iterator.prototype[Symbol.toStringTag]");
Assert.assertEquals("Iterator", result.asString());

result = context.eval(JavaScriptLanguage.ID, "Iterator.prototype[Symbol.toStringTag] = 'Changed'; Iterator.prototype[Symbol.toStringTag]");
Assert.assertEquals("Changed", result.asString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public JSDynamicObject createPrototype(JSRealm realm, JSFunctionObject ctor) {

JSObjectUtil.putConstructorProperty(ctx, iteratorPrototype, ctor);
JSObjectUtil.putFunctionsFromContainer(realm, iteratorPrototype, AsyncIteratorPrototypeBuiltins.BUILTINS);
JSObjectUtil.putToStringTag(iteratorPrototype, TO_STRING_NAME);
JSObjectUtil.putDataProperty(iteratorPrototype, Symbol.SYMBOL_TO_STRING_TAG, TO_STRING_NAME, JSAttributes.getDefaultNotEnumerable());
JSObjectUtil.putDataProperty(realm.getContext(), iteratorPrototype, Symbol.SYMBOL_ASYNC_ITERATOR, createIteratorPrototypeSymbolIteratorFunction(realm), JSAttributes.getDefaultNotEnumerable());

return iteratorPrototype;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public JSDynamicObject createPrototype(JSRealm realm, JSFunctionObject ctor) {

JSObjectUtil.putConstructorProperty(ctx, iteratorPrototype, ctor);
JSObjectUtil.putFunctionsFromContainer(realm, iteratorPrototype, IteratorPrototypeBuiltins.BUILTINS);
JSObjectUtil.putToStringTag(iteratorPrototype, CLASS_NAME);
JSObjectUtil.putDataProperty(iteratorPrototype, Symbol.SYMBOL_TO_STRING_TAG, CLASS_NAME, JSAttributes.getDefaultNotEnumerable());
JSObjectUtil.putDataProperty(realm.getContext(), iteratorPrototype, Symbol.SYMBOL_ITERATOR, createIteratorPrototypeSymbolIteratorFunction(realm), JSAttributes.getDefaultNotEnumerable());

return iteratorPrototype;
Expand Down

0 comments on commit 8e5fe59

Please sign in to comment.