Bug 645416, part 27 - Implement Object.getOwnPropertySymbols(). r=Waldo.

This commit is contained in:
Jason Orendorff
2014-06-23 10:57:03 -05:00
parent b352550168
commit 79ded004dc
7 changed files with 191 additions and 80 deletions

View File

@@ -650,23 +650,10 @@ Trap(JSContext *cx, HandleObject handler, HandleValue fval, unsigned argc, Value
return Invoke(cx, ObjectValue(*handler), fval, argc, argv, rval);
}
static bool
IdToExposableValue(JSContext *cx, HandleId id, MutableHandleValue value)
{
value.set(IdToValue(id)); // Re-use out-param to avoid Rooted overhead.
if (value.isSymbol())
return true;
JSString *name = ToString<CanGC>(cx, value);
if (!name)
return false;
value.setString(name);
return true;
}
static bool
Trap1(JSContext *cx, HandleObject handler, HandleValue fval, HandleId id, MutableHandleValue rval)
{
if (!IdToExposableValue(cx, id, rval)) // Re-use out-param to avoid Rooted overhead.
if (!IdToStringOrSymbol(cx, id, rval))
return false;
return Trap(cx, handler, fval, 1, rval.address(), rval);
}
@@ -676,7 +663,7 @@ Trap2(JSContext *cx, HandleObject handler, HandleValue fval, HandleId id, Value
MutableHandleValue rval)
{
RootedValue v(cx, v_);
if (!IdToExposableValue(cx, id, rval)) // Re-use out-param to avoid Rooted overhead.
if (!IdToStringOrSymbol(cx, id, rval))
return false;
JS::AutoValueArray<2> argv(cx);
argv[0].set(rval);
@@ -950,7 +937,7 @@ ScriptedIndirectProxyHandler::get(JSContext *cx, HandleObject proxy, HandleObjec
{
RootedObject handler(cx, GetIndirectProxyHandlerObject(proxy));
RootedValue idv(cx);
if (!IdToExposableValue(cx, id, &idv))
if (!IdToStringOrSymbol(cx, id, &idv))
return false;
JS::AutoValueArray<2> argv(cx);
argv[0].setObjectOrNull(receiver);
@@ -969,7 +956,7 @@ ScriptedIndirectProxyHandler::set(JSContext *cx, HandleObject proxy, HandleObjec
{
RootedObject handler(cx, GetIndirectProxyHandlerObject(proxy));
RootedValue idv(cx);
if (!IdToExposableValue(cx, id, &idv))
if (!IdToStringOrSymbol(cx, id, &idv))
return false;
JS::AutoValueArray<3> argv(cx);
argv[0].setObjectOrNull(receiver);
@@ -1465,7 +1452,7 @@ ScriptedDirectProxyHandler::getOwnPropertyDescriptor(JSContext *cx, HandleObject
// step 8-9
RootedValue propKey(cx);
if (!IdToExposableValue(cx, id, &propKey))
if (!IdToStringOrSymbol(cx, id, &propKey))
return false;
Value argv[] = {
@@ -1588,7 +1575,7 @@ ScriptedDirectProxyHandler::defineProperty(JSContext *cx, HandleObject proxy, Ha
// step 10, 12
RootedValue propKey(cx);
if (!IdToExposableValue(cx, id, &propKey))
if (!IdToStringOrSymbol(cx, id, &propKey))
return false;
Value argv[] = {
@@ -1711,7 +1698,7 @@ ScriptedDirectProxyHandler::delete_(JSContext *cx, HandleObject proxy, HandleId
// step 8
RootedValue value(cx);
if (!IdToExposableValue(cx, id, &value))
if (!IdToStringOrSymbol(cx, id, &value))
return false;
Value argv[] = {
ObjectValue(*target),
@@ -1809,7 +1796,7 @@ ScriptedDirectProxyHandler::has(JSContext *cx, HandleObject proxy, HandleId id,
// step 5
RootedValue value(cx);
if (!IdToExposableValue(cx, id, &value))
if (!IdToStringOrSymbol(cx, id, &value))
return false;
Value argv[] = {
ObjectOrNullValue(target),
@@ -1871,7 +1858,7 @@ ScriptedDirectProxyHandler::get(JSContext *cx, HandleObject proxy, HandleObject
// step 5
RootedValue value(cx);
if (!IdToExposableValue(cx, id, &value))
if (!IdToStringOrSymbol(cx, id, &value))
return false;
Value argv[] = {
ObjectOrNullValue(target),
@@ -1934,7 +1921,7 @@ ScriptedDirectProxyHandler::set(JSContext *cx, HandleObject proxy, HandleObject
// step 5
RootedValue value(cx);
if (!IdToExposableValue(cx, id, &value))
if (!IdToStringOrSymbol(cx, id, &value))
return false;
Value argv[] = {
ObjectOrNullValue(target),