Attachment #650295: Part 11 - Implement auxiliary functions 1-4 for bug #703537

View | Details | Raw Unified | Return to bug 703537
Collapse All | Expand All

(-)a/js/src/jsobj.cpp (+32 lines)
Line     Link Here 
 Lines 1372-1387   PropDesc::initialize(JSContext *cx, cons Link Here 
1372
        return false;
1372
        return false;
1373
    }
1373
    }
1374
1374
1375
    JS_ASSERT_IF(attrs & JSPROP_READONLY, !(attrs & (JSPROP_GETTER | JSPROP_SETTER)));
1375
    JS_ASSERT_IF(attrs & JSPROP_READONLY, !(attrs & (JSPROP_GETTER | JSPROP_SETTER)));
1376
1376
1377
    return true;
1377
    return true;
1378
}
1378
}
1379
1379
1380
void
1381
PropDesc::complete()
1382
{
1383
    if (isGenericDescriptor() || isDataDescriptor()) {
1384
        if (!hasValue_) {
1385
            hasValue_ = true;
1386
            value_.setUndefined();
1387
        }
1388
        if (!hasWritable_) {
1389
            hasWritable_ = true;
1390
            attrs |= JSPROP_READONLY;
1391
        }
1392
    } else {
1393
        if (!hasGet_) {
1394
            hasGet_ = true;
1395
            get_.setUndefined();
1396
        }
1397
        if (!hasSet_) {
1398
            hasSet_ = true;
1399
            set_.setUndefined();
1400
        }
1401
    }
1402
    if (!hasEnumerable_) {
1403
        hasEnumerable_ = true;
1404
        attrs |= JSPROP_ENUMERATE;
1405
    }
1406
    if (!hasConfigurable_) {
1407
        hasConfigurable_ = true;
1408
        attrs &= ~JSPROP_PERMANENT;
1409
    }
1410
}
1411
1380
namespace js {
1412
namespace js {
1381
1413
1382
bool
1414
bool
1383
Throw(JSContext *cx, jsid id, unsigned errorNumber)
1415
Throw(JSContext *cx, jsid id, unsigned errorNumber)
1384
{
1416
{
1385
    JS_ASSERT(js_ErrorFormatString[errorNumber].argCount == 1);
1417
    JS_ASSERT(js_ErrorFormatString[errorNumber].argCount == 1);
1386
1418
1387
    JSString *idstr = IdToString(cx, id);
1419
    JSString *idstr = IdToString(cx, id);
(-)a/js/src/jsproxy.cpp (+87 lines)
Line     Link Here 
 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
}
(-)a/js/src/vm/ObjectImpl.h (-1 / +10 lines)
Line     Link Here 
 Lines 163-179   struct PropDesc { Link Here 
163
     *
163
     *
164
     * If checkAccessors is false, skip steps 7.b and 8.b, which throw a
164
     * If checkAccessors is false, skip steps 7.b and 8.b, which throw a
165
     * TypeError if .get or .set is neither a callable object nor undefined.
165
     * TypeError if .get or .set is neither a callable object nor undefined.
166
     *
166
     *
167
     * (DebuggerObject_defineProperty uses this: the .get and .set properties
167
     * (DebuggerObject_defineProperty uses this: the .get and .set properties
168
     * are expected to be Debugger.Object wrappers of functions, which are not
168
     * are expected to be Debugger.Object wrappers of functions, which are not
169
     * themselves callable.)
169
     * themselves callable.)
170
     */
170
     */
171
    bool initialize(JSContext* cx, const Value &v, bool checkAccessors = true);
171
    bool initialize(JSContext *cx, const Value &v, bool checkAccessors = true);
172
173
    /*
174
     * If IsGenericDescriptor(desc) or IsDataDescriptor(desc) is true, then if
175
     * the value of an attribute field of desc, considered as a data
176
     * descriptor, is absent, set it to its default value. Else if the value of
177
     * an attribute field of desc, considered as an attribute descriptor, is
178
     * absent, set it to its default value.
179
     */
180
    void complete();
172
181
173
    /*
182
    /*
174
     * 8.10.4 FromPropertyDescriptor(Desc)
183
     * 8.10.4 FromPropertyDescriptor(Desc)
175
     *
184
     *
176
     * initFromPropertyDescriptor sets pd to undefined and populates all the
185
     * initFromPropertyDescriptor sets pd to undefined and populates all the
177
     * other fields of this PropDesc from desc.
186
     * other fields of this PropDesc from desc.
178
     *
187
     *
179
     * makeObject populates pd based on the other fields of *this, creating a
188
     * makeObject populates pd based on the other fields of *this, creating a

Return to bug 703537