-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ADD: ES6 Object.values / Object.entries / Object.fromEntries #902
Changes from 2 commits
ae236ba
6a913ed
b4817f0
0fed865
d3c13ea
afe2274
2fb4633
5cdf431
88d40c6
3b2e52f
265f5ca
8fa46fa
f0e20c9
c915eea
37b6fee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -438,20 +438,39 @@ public Object execIdCall( | |
if (key == Scriptable.NOT_FOUND) { | ||
key = Undefined.instance; | ||
} | ||
if (key instanceof ScriptableObject) { | ||
ScriptableObject so = (ScriptableObject) key; | ||
if (so.has(SymbolKey.TO_PRIMITIVE, so)) { | ||
key = so.get(SymbolKey.TO_PRIMITIVE, so); | ||
} | ||
} | ||
if (key instanceof Function) { | ||
Function fun = (Function)key; | ||
key = fun.call(cx, fun.getParentScope(), entry, ScriptRuntime.emptyArgs); | ||
Function fun = (Function) key; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test Can someone point out, where this happens in https://tc39.es/ecma262/#sec-object.fromentries ? I assume it may happen in "ToPrimitive", but I use |
||
key = | ||
fun.call( | ||
cx, | ||
fun.getParentScope(), | ||
entry, | ||
new Object[] {"string"}); | ||
} | ||
Object value = entry.get(1, entry); | ||
if (value == Scriptable.NOT_FOUND) { | ||
value = Undefined.instance; | ||
} | ||
if (value instanceof Function) { | ||
Function fun = (Function)value; | ||
value = fun.call(cx, fun.getParentScope(), entry, ScriptRuntime.emptyArgs); | ||
Function fun = (Function) value; | ||
value = | ||
fun.call( | ||
cx, | ||
fun.getParentScope(), | ||
entry, | ||
ScriptRuntime.emptyArgs); | ||
} | ||
|
||
if (key instanceof Integer) { | ||
obj.put((Integer) key, obj, value); | ||
} else if (key instanceof Symbol && obj instanceof SymbolScriptable) { | ||
((SymbolScriptable) obj).put((Symbol) key, obj, value); | ||
} else { | ||
obj.put(ScriptRuntime.toString(key), obj, value); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4291,23 +4291,29 @@ public static Scriptable newObjectLiteral( | |
Object id = propertyIds[i]; | ||
int getterSetter = getterSetters == null ? 0 : getterSetters[i]; | ||
Object value = propertyValues[i]; | ||
if (id instanceof String) { | ||
if (id instanceof Symbol) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Required to support arrays like this:
|
||
Symbol sym = (Symbol) id; | ||
SymbolScriptable so = (SymbolScriptable) object; | ||
so.put(sym, object, value); | ||
} else if (id instanceof Integer) { | ||
int index = ((Integer) id).intValue(); | ||
object.put(index, object, value); | ||
} else { | ||
// we might get a computed double. | ||
String stringId = ScriptRuntime.toString(id); | ||
if (getterSetter == 0) { | ||
if (isSpecialProperty((String) id)) { | ||
Ref ref = specialRef(object, (String) id, cx, scope); | ||
if (isSpecialProperty(stringId)) { | ||
Ref ref = specialRef(object, stringId, cx, scope); | ||
ref.set(cx, scope, value); | ||
} else { | ||
object.put((String) id, object, value); | ||
object.put(stringId, object, value); | ||
} | ||
} else { | ||
ScriptableObject so = (ScriptableObject) object; | ||
Callable getterOrSetter = (Callable) value; | ||
boolean isSetter = getterSetter == 1; | ||
so.setGetterOrSetter((String) id, 0, getterOrSetter, isSetter); | ||
} | ||
} else { | ||
int index = ((Integer) id).intValue(); | ||
object.put(index, object, value); | ||
} | ||
} | ||
return object; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edge case? if object has
Symbol.toPrimitive
-> take it.Shouldn't this be handled by
ScriptRuntime.toPrimitive
- respectivelyScriptableObject.getDefaultValue
?