|
|
|
Lines 1041-1056
class ScriptedDirectProxyHandler : publi
|
Link Here
|
|---|
|
| 1041 |
virtual bool keys(JSContext *cx, JSObject *proxy, AutoIdVector &props); |
1041 |
virtual bool keys(JSContext *cx, JSObject *proxy, AutoIdVector &props); |
| 1042 |
virtual bool iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp); |
1042 |
virtual bool iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp); |
| 1043 |
|
1043 |
|
| 1044 |
static ScriptedDirectProxyHandler singleton; |
1044 |
static ScriptedDirectProxyHandler singleton; |
| 1045 |
}; |
1045 |
}; |
| 1046 |
|
1046 |
|
| 1047 |
static int sScriptedDirectProxyHandlerFamily = 0; |
1047 |
static int sScriptedDirectProxyHandlerFamily = 0; |
| 1048 |
|
1048 |
|
|
|
1049 |
/* Aux.2 FromGenericPropertyDescriptor(Desc) */ |
| 1050 |
static bool |
| 1051 |
FromGenericPropertyDescriptor(JSContext *cx, PropDesc *desc, MutableHandleValue rval) |
| 1052 |
{ |
| 1053 |
/* Aux.2 step 1 */ |
| 1054 |
if (desc->isUndefined()) { |
| 1055 |
rval.setUndefined(); |
| 1056 |
return true; |
| 1057 |
} |
| 1058 |
|
| 1059 |
/* Aux.2 steps 3-9 */ |
| 1060 |
if (!desc->makeObject(cx)) |
| 1061 |
return false; |
| 1062 |
*rval.address() = desc->pd(); |
| 1063 |
return true; |
| 1064 |
} |
| 1065 |
|
| 1066 |
/* |
| 1067 |
* Aux.3 NormalizePropertyDescriptor(Attributes) |
| 1068 |
* |
| 1069 |
* NOTE: to minimize code duplication, the code for this function is shared with |
| 1070 |
* that for Aux.4 NormalizeAndCompletePropertyDescriptor (see below). The |
| 1071 |
* argument complete is used to distinguish between the two. |
| 1072 |
*/ |
| 1073 |
static bool |
| 1074 |
NormalizePropertyDescriptor(JSContext *cx, MutableHandleValue vp, bool complete = false) |
| 1075 |
{ |
| 1076 |
/* Aux.4 step 1 */ |
| 1077 |
if (complete && vp.isUndefined()) |
| 1078 |
return true; |
| 1079 |
|
| 1080 |
/* Aux.3 steps 1-2 / Aux.4 steps 2-3 */ |
| 1081 |
AutoPropDescArrayRooter descs(cx); |
| 1082 |
PropDesc *desc = descs.append(); |
| 1083 |
if (!desc || !desc->initialize(cx, *vp.address())) |
| 1084 |
return false; |
| 1085 |
if (complete) |
| 1086 |
desc->complete(); |
| 1087 |
|
| 1088 |
/* |
| 1089 |
* Aux.3 step 3 / Aux.4 step 4 |
| 1090 |
* |
| 1091 |
* NOTE: Aux.4 step 4 actually specifies FromPropertyDescriptor here. |
| 1092 |
* However, the way FromPropertyDescriptor is implemented (PropDesc:: |
| 1093 |
* makeObject) is actually closer to FromGenericPropertyDescriptor, |
| 1094 |
* and is in fact used to implement the latter, so we might as well call it |
| 1095 |
* directly. |
| 1096 |
*/ |
| 1097 |
if (!FromGenericPropertyDescriptor(cx, desc, vp)) |
| 1098 |
return false; |
| 1099 |
if (vp.isUndefined()) |
| 1100 |
return true; |
| 1101 |
RootedObject descObj(cx, &vp.toObject()); |
| 1102 |
|
| 1103 |
/* Aux.3 steps 4-5 / Aux.4 steps 5-6 */ |
| 1104 |
AutoIdVector props(cx); |
| 1105 |
if (!GetPropertyNames(cx, descObj, JSITER_OWNONLY, &props)) |
| 1106 |
return false; |
| 1107 |
size_t n = props.length(); |
| 1108 |
for (size_t i = 0; i < n; ++n) { |
| 1109 |
RootedId id(cx, props[i]); |
| 1110 |
if (JSID_IS_ATOM(id)) { |
| 1111 |
JSAtom *atom = JSID_TO_ATOM(id); |
| 1112 |
const JSAtomState &atomState = cx->runtime->atomState; |
| 1113 |
if (atom == atomState.valueAtom || atom == atomState.writableAtom || |
| 1114 |
atom == atomState.getAtom || atom == atomState.setAtom || |
| 1115 |
atom == atomState.enumerableAtom || atom == atomState.configurableAtom) { |
| 1116 |
continue; |
| 1117 |
} |
| 1118 |
} |
| 1119 |
|
| 1120 |
RootedValue v(cx); |
| 1121 |
if (!descObj->getGeneric(cx, descObj, id, &v)) |
| 1122 |
return false; |
| 1123 |
if (!JS_DefinePropertyById(cx, descObj, id, v, NULL, NULL, JSPROP_ENUMERATE)) |
| 1124 |
return false; |
| 1125 |
} |
| 1126 |
return true; |
| 1127 |
} |
| 1128 |
|
| 1129 |
/* Aux.4 NormalizeAndCompletePropertyDescriptor(Attributes) */ |
| 1130 |
static inline bool |
| 1131 |
NormalizeAndCompletePropertyDescriptor(JSContext *cx, MutableHandleValue vp) |
| 1132 |
{ |
| 1133 |
return NormalizePropertyDescriptor(cx, vp, true); |
| 1134 |
} |
| 1135 |
|
| 1049 |
ScriptedDirectProxyHandler::ScriptedDirectProxyHandler() |
1136 |
ScriptedDirectProxyHandler::ScriptedDirectProxyHandler() |
| 1050 |
: DirectProxyHandler(&sScriptedDirectProxyHandlerFamily) |
1137 |
: DirectProxyHandler(&sScriptedDirectProxyHandlerFamily) |
| 1051 |
{ |
1138 |
{ |
| 1052 |
} |
1139 |
} |
| 1053 |
|
1140 |
|
| 1054 |
ScriptedDirectProxyHandler::~ScriptedDirectProxyHandler() |
1141 |
ScriptedDirectProxyHandler::~ScriptedDirectProxyHandler() |
| 1055 |
{ |
1142 |
{ |
| 1056 |
} |
1143 |
} |