Attachment #607088: Intermediate patch (Proxy constructor) for bug #703537

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

(-)a/js/src/jsapi-tests/testBug604087.cpp (-3 / +3 lines)
Line     Link Here 
 Lines 53-77   BEGIN_TEST(testBug604087) Link Here 
53
    JSObject *outerObj = js::Wrapper::New(cx, global, global->getProto(), global,
53
    JSObject *outerObj = js::Wrapper::New(cx, global, global->getProto(), global,
54
                                          &OuterWrapper::singleton);
54
                                          &OuterWrapper::singleton);
55
    JSObject *compartment2 = JS_NewCompartmentAndGlobalObject(cx, getGlobalClass(), NULL);
55
    JSObject *compartment2 = JS_NewCompartmentAndGlobalObject(cx, getGlobalClass(), NULL);
56
    JSObject *compartment3 = JS_NewCompartmentAndGlobalObject(cx, getGlobalClass(), NULL);
56
    JSObject *compartment3 = JS_NewCompartmentAndGlobalObject(cx, getGlobalClass(), NULL);
57
    JSObject *compartment4 = JS_NewCompartmentAndGlobalObject(cx, getGlobalClass(), NULL);
57
    JSObject *compartment4 = JS_NewCompartmentAndGlobalObject(cx, getGlobalClass(), NULL);
58
58
59
    JSObject *c2wrapper = wrap(cx, outerObj, compartment2);
59
    JSObject *c2wrapper = wrap(cx, outerObj, compartment2);
60
    CHECK(c2wrapper);
60
    CHECK(c2wrapper);
61
    js::SetProxyExtra(c2wrapper, 0, js::Int32Value(2));
61
    js::SetProxyExtra(c2wrapper, js::Int32Value(2));
62
62
63
    JSObject *c3wrapper = wrap(cx, outerObj, compartment3);
63
    JSObject *c3wrapper = wrap(cx, outerObj, compartment3);
64
    CHECK(c3wrapper);
64
    CHECK(c3wrapper);
65
    js::SetProxyExtra(c3wrapper, 0, js::Int32Value(3));
65
    js::SetProxyExtra(c3wrapper, js::Int32Value(3));
66
66
67
    JSObject *c4wrapper = wrap(cx, outerObj, compartment4);
67
    JSObject *c4wrapper = wrap(cx, outerObj, compartment4);
68
    CHECK(c4wrapper);
68
    CHECK(c4wrapper);
69
    js::SetProxyExtra(c4wrapper, 0, js::Int32Value(4));
69
    js::SetProxyExtra(c4wrapper, js::Int32Value(4));
70
    compartment4 = c4wrapper = NULL;
70
    compartment4 = c4wrapper = NULL;
71
71
72
    JSObject *next;
72
    JSObject *next;
73
    {
73
    {
74
        JSAutoEnterCompartment ac;
74
        JSAutoEnterCompartment ac;
75
        CHECK(ac.enter(cx, compartment2));
75
        CHECK(ac.enter(cx, compartment2));
76
        next = js::Wrapper::New(cx, compartment2, compartment2->getProto(), compartment2,
76
        next = js::Wrapper::New(cx, compartment2, compartment2->getProto(), compartment2,
77
                                &OuterWrapper::singleton);
77
                                &OuterWrapper::singleton);
(-)a/js/src/jscompartment.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 309-325   JSCompartment::wrap(JSContext *cx, Value Link Here 
309
    if (!wrapper)
309
    if (!wrapper)
310
        return false;
310
        return false;
311
311
312
    vp->setObject(*wrapper);
312
    vp->setObject(*wrapper);
313
313
314
    if (wrapper->getProto() != proto && !SetProto(cx, wrapper, proto, false))
314
    if (wrapper->getProto() != proto && !SetProto(cx, wrapper, proto, false))
315
        return false;
315
        return false;
316
316
317
    if (!crossCompartmentWrappers.put(GetProxyPrivate(wrapper), *vp))
317
    if (!crossCompartmentWrappers.put(GetProxyTargetValue(wrapper), *vp))
318
        return false;
318
        return false;
319
319
320
    if (!wrapper->setParent(cx, global))
320
    if (!wrapper->setParent(cx, global))
321
        return false;
321
        return false;
322
    return true;
322
    return true;
323
}
323
}
324
324
325
bool
325
bool
(-)a/js/src/jsproxy.cpp (-12 / +52 lines)
Line     Link Here 
 Lines 587-603   ReturnedValueMustNotBePrimitive(JSContex Link Here 
587
    }
587
    }
588
    return true;
588
    return true;
589
}
589
}
590
590
591
static JSObject *
591
static JSObject *
592
GetProxyHandlerObject(JSContext *cx, JSObject *proxy)
592
GetProxyHandlerObject(JSContext *cx, JSObject *proxy)
593
{
593
{
594
    JS_ASSERT(OperationInProgress(cx, proxy));
594
    JS_ASSERT(OperationInProgress(cx, proxy));
595
    return GetProxyPrivate(proxy).toObjectOrNull();
595
    return GetProxyHandlerValue(proxy).toObjectOrNull();
596
}
596
}
597
597
598
bool
598
bool
599
ScriptedProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
599
ScriptedProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
600
                                            PropertyDescriptor *desc)
600
                                            PropertyDescriptor *desc)
601
{
601
{
602
    JSObject *handler = GetProxyHandlerObject(cx, proxy);
602
    JSObject *handler = GetProxyHandlerObject(cx, proxy);
603
    AutoValueRooter tvr(cx);
603
    AutoValueRooter tvr(cx);
 Lines 1007-1023   Proxy::iteratorNext(JSContext *cx, JSObj Link Here 
1007
    JS_CHECK_RECURSION(cx, return NULL);
1007
    JS_CHECK_RECURSION(cx, return NULL);
1008
    AutoPendingProxyOperation pending(cx, proxy);
1008
    AutoPendingProxyOperation pending(cx, proxy);
1009
    return GetProxyHandler(proxy)->iteratorNext(cx, proxy, vp);
1009
    return GetProxyHandler(proxy)->iteratorNext(cx, proxy, vp);
1010
}
1010
}
1011
1011
1012
static JSObject *
1012
static JSObject *
1013
proxy_innerObject(JSContext *cx, JSObject *obj)
1013
proxy_innerObject(JSContext *cx, JSObject *obj)
1014
{
1014
{
1015
    return GetProxyPrivate(obj).toObjectOrNull();
1015
    return GetProxyHandlerValue(obj).toObjectOrNull();
1016
}
1016
}
1017
1017
1018
static JSBool
1018
static JSBool
1019
proxy_LookupGeneric(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
1019
proxy_LookupGeneric(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
1020
                    JSProperty **propp)
1020
                    JSProperty **propp)
1021
{
1021
{
1022
    id = js_CheckForStringIndex(id);
1022
    id = js_CheckForStringIndex(id);
1023
1023
 Lines 1263-1281   proxy_DeleteSpecial(JSContext *cx, JSObj Link Here 
1263
{
1263
{
1264
    return proxy_DeleteGeneric(cx, obj, SPECIALID_TO_JSID(sid), rval, strict);
1264
    return proxy_DeleteGeneric(cx, obj, SPECIALID_TO_JSID(sid), rval, strict);
1265
}
1265
}
1266
1266
1267
static void
1267
static void
1268
proxy_TraceObject(JSTracer *trc, JSObject *obj)
1268
proxy_TraceObject(JSTracer *trc, JSObject *obj)
1269
{
1269
{
1270
    GetProxyHandler(obj)->trace(trc, obj);
1270
    GetProxyHandler(obj)->trace(trc, obj);
1271
    MarkCrossCompartmentSlot(trc, &obj->getReservedSlotRef(JSSLOT_PROXY_PRIVATE), "private");
1271
    MarkCrossCompartmentSlot(trc, &obj->getReservedSlotRef(JSSLOT_PROXY_TARGET_VALUE), "target");
1272
    MarkCrossCompartmentSlot(trc, &obj->getReservedSlotRef(JSSLOT_PROXY_EXTRA + 0), "extra0");
1272
    MarkCrossCompartmentSlot(trc, &obj->getReservedSlotRef(JSSLOT_PROXY_HANDLER_VALUE), "handler");
1273
    MarkCrossCompartmentSlot(trc, &obj->getReservedSlotRef(JSSLOT_PROXY_EXTRA + 1), "extra1");
1273
    MarkCrossCompartmentSlot(trc, &obj->getReservedSlotRef(JSSLOT_PROXY_EXTRA), "extra");
1274
}
1274
}
1275
1275
1276
static void
1276
static void
1277
proxy_TraceFunction(JSTracer *trc, JSObject *obj)
1277
proxy_TraceFunction(JSTracer *trc, JSObject *obj)
1278
{
1278
{
1279
    MarkCrossCompartmentSlot(trc, &GetCall(obj), "call");
1279
    MarkCrossCompartmentSlot(trc, &GetCall(obj), "call");
1280
    MarkCrossCompartmentSlot(trc, &GetFunctionProxyConstruct(obj), "construct");
1280
    MarkCrossCompartmentSlot(trc, &GetFunctionProxyConstruct(obj), "construct");
1281
    proxy_TraceObject(trc, obj);
1281
    proxy_TraceObject(trc, obj);
 Lines 1507-1524   JS_FRIEND_DATA(Class) js::FunctionProxyC Link Here 
1507
        proxy_TypeOf,
1507
        proxy_TypeOf,
1508
        proxy_Fix,           /* fix             */
1508
        proxy_Fix,           /* fix             */
1509
        NULL,                /* thisObject      */
1509
        NULL,                /* thisObject      */
1510
        NULL,                /* clear           */
1510
        NULL,                /* clear           */
1511
    }
1511
    }
1512
};
1512
};
1513
1513
1514
JS_FRIEND_API(JSObject *)
1514
JS_FRIEND_API(JSObject *)
1515
js::NewProxyObject(JSContext *cx, ProxyHandler *handler, const Value &priv, JSObject *proto,
1515
js::NewProxyObject(JSContext *cx, ProxyHandler *handler,
1516
                   JSObject *parent, JSObject *call, JSObject *construct)
1516
                   const Value &targetValue, const Value &handlerValue,
1517
                   JSObject *proto, JSObject *parent, JSObject *call,
1518
                   JSObject *construct)
1517
{
1519
{
1518
    JS_ASSERT_IF(proto, cx->compartment == proto->compartment());
1520
    JS_ASSERT_IF(proto, cx->compartment == proto->compartment());
1519
    JS_ASSERT_IF(parent, cx->compartment == parent->compartment());
1521
    JS_ASSERT_IF(parent, cx->compartment == parent->compartment());
1520
    bool fun = call || construct;
1522
    bool fun = call || construct;
1521
    Class *clasp;
1523
    Class *clasp;
1522
    if (fun)
1524
    if (fun)
1523
        clasp = &FunctionProxyClass;
1525
        clasp = &FunctionProxyClass;
1524
    else
1526
    else
 Lines 1531-1547   js::NewProxyObject(JSContext *cx, ProxyH Link Here 
1531
     */
1533
     */
1532
    if (proto && !proto->setNewTypeUnknown(cx))
1534
    if (proto && !proto->setNewTypeUnknown(cx))
1533
        return NULL;
1535
        return NULL;
1534
1536
1535
    JSObject *obj = NewObjectWithGivenProto(cx, clasp, proto, parent);
1537
    JSObject *obj = NewObjectWithGivenProto(cx, clasp, proto, parent);
1536
    if (!obj)
1538
    if (!obj)
1537
        return NULL;
1539
        return NULL;
1538
    obj->setSlot(JSSLOT_PROXY_HANDLER, PrivateValue(handler));
1540
    obj->setSlot(JSSLOT_PROXY_HANDLER, PrivateValue(handler));
1539
    obj->setSlot(JSSLOT_PROXY_PRIVATE, priv);
1541
    obj->setSlot(JSSLOT_PROXY_TARGET_VALUE, targetValue);
1542
    obj->setSlot(JSSLOT_PROXY_HANDLER_VALUE, handlerValue);
1540
    if (fun) {
1543
    if (fun) {
1541
        obj->setSlot(JSSLOT_PROXY_CALL, call ? ObjectValue(*call) : UndefinedValue());
1544
        obj->setSlot(JSSLOT_PROXY_CALL, call ? ObjectValue(*call) : UndefinedValue());
1542
        if (construct) {
1545
        if (construct) {
1543
            obj->setSlot(JSSLOT_PROXY_CONSTRUCT, ObjectValue(*construct));
1546
            obj->setSlot(JSSLOT_PROXY_CONSTRUCT, ObjectValue(*construct));
1544
        }
1547
        }
1545
    }
1548
    }
1546
1549
1547
    /* Don't track types of properties of proxies. */
1550
    /* Don't track types of properties of proxies. */
 Lines 1566-1583   proxy_create(JSContext *cx, unsigned arg Link Here 
1566
        proto = &vp[3].toObject();
1569
        proto = &vp[3].toObject();
1567
        parent = proto->getParent();
1570
        parent = proto->getParent();
1568
    } else {
1571
    } else {
1569
        JS_ASSERT(IsFunctionObject(vp[0]));
1572
        JS_ASSERT(IsFunctionObject(vp[0]));
1570
        proto = NULL;
1573
        proto = NULL;
1571
    }
1574
    }
1572
    if (!parent)
1575
    if (!parent)
1573
        parent = vp[0].toObject().getParent();
1576
        parent = vp[0].toObject().getParent();
1574
    JSObject *proxy = NewProxyObject(cx, &ScriptedProxyHandler::singleton, ObjectValue(*handler),
1577
    JSObject *proxy = NewProxyObject(cx, &ScriptedProxyHandler::singleton,
1575
                                     proto, parent);
1578
                                     ObjectValue(*handler),
1579
                                     ObjectValue(*handler), proto, parent);
1576
    if (!proxy)
1580
    if (!proxy)
1577
        return false;
1581
        return false;
1578
1582
1579
    vp->setObject(*proxy);
1583
    vp->setObject(*proxy);
1580
    return true;
1584
    return true;
1581
}
1585
}
1582
1586
1583
static JSBool
1587
static JSBool
 Lines 1605-1621   proxy_createFunction(JSContext *cx, unsi Link Here 
1605
    if (argc > 2) {
1609
    if (argc > 2) {
1606
        construct = js_ValueToCallableObject(cx, &vp[4], JSV2F_SEARCH_STACK);
1610
        construct = js_ValueToCallableObject(cx, &vp[4], JSV2F_SEARCH_STACK);
1607
        if (!construct)
1611
        if (!construct)
1608
            return false;
1612
            return false;
1609
    }
1613
    }
1610
1614
1611
    JSObject *proxy = NewProxyObject(cx, &ScriptedProxyHandler::singleton,
1615
    JSObject *proxy = NewProxyObject(cx, &ScriptedProxyHandler::singleton,
1612
                                     ObjectValue(*handler),
1616
                                     ObjectValue(*handler),
1613
                                     proto, parent, call, construct);
1617
                                     ObjectValue(*handler), proto, parent, call,
1618
                                     construct);
1614
    if (!proxy)
1619
    if (!proxy)
1615
        return false;
1620
        return false;
1616
1621
1617
    vp->setObject(*proxy);
1622
    vp->setObject(*proxy);
1618
    return true;
1623
    return true;
1619
}
1624
}
1620
1625
1621
#ifdef DEBUG
1626
#ifdef DEBUG
 Lines 1798-1823   FixProxy(JSContext *cx, JSObject *proxy, Link Here 
1798
        return false;
1803
        return false;
1799
1804
1800
    /* The GC will dispose of the proxy object. */
1805
    /* The GC will dispose of the proxy object. */
1801
1806
1802
    *bp = true;
1807
    *bp = true;
1803
    return true;
1808
    return true;
1804
}
1809
}
1805
1810
1811
JSBool
1812
js_Proxy(JSContext *cx, unsigned argc, Value *vp)
1813
{
1814
    if (argc < 1) {
1815
        JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_MORE_ARGS_NEEDED,
1816
                             "Proxy", "0", "s");
1817
        return false;
1818
    }
1819
    JSObject *target = NonNullObject(cx, vp[2]);
1820
    if (!target)
1821
        return false;
1822
    JSObject *handler = NULL;
1823
    if (argc > 1 && vp[3].isObject())
1824
        handler = &vp[3].toObject();
1825
    JSObject *proto = NULL;
1826
    JSObject *parent = vp[0].toObject().getParent();
1827
    if (target->isFunction()) {
1828
        proto = parent->global().getOrCreateFunctionPrototype(cx);
1829
        if (!proto)
1830
            return false;
1831
        parent = proto->getParent();
1832
    } 
1833
    JSObject *proxy = NewProxyObject(cx, &ScriptedProxyHandler::singleton,
1834
                                     ObjectValue(*target), ObjectValue(*handler),
1835
                                     proto, parent, NULL, NULL);
1836
    if (!proxy)
1837
        return false;
1838
    vp->setObject(*proxy);
1839
    return true;
1840
}
1841
1806
Class js::ProxyClass = {
1842
Class js::ProxyClass = {
1807
    "Proxy",
1843
    "Proxy",
1808
    JSCLASS_HAS_CACHED_PROTO(JSProto_Proxy),
1844
    JSCLASS_HAS_CACHED_PROTO(JSProto_Proxy),
1809
    JS_PropertyStub,         /* addProperty */
1845
    JS_PropertyStub,         /* addProperty */
1810
    JS_PropertyStub,         /* delProperty */
1846
    JS_PropertyStub,         /* delProperty */
1811
    JS_PropertyStub,         /* getProperty */
1847
    JS_PropertyStub,         /* getProperty */
1812
    JS_StrictPropertyStub,   /* setProperty */
1848
    JS_StrictPropertyStub,   /* setProperty */
1813
    JS_EnumerateStub,
1849
    JS_EnumerateStub,
1814
    JS_ResolveStub,
1850
    JS_ResolveStub,
1815
    JS_ConvertStub
1851
    JS_ConvertStub,
1852
    NULL,                    /* finalize    */
1853
    NULL,                    /* checkAccess */
1854
    js_Proxy,                /* call        */
1855
    js_Proxy                 /* construct   */
1816
};
1856
};
1817
1857
1818
JS_FRIEND_API(JSObject *)
1858
JS_FRIEND_API(JSObject *)
1819
js_InitProxyClass(JSContext *cx, JSObject *obj)
1859
js_InitProxyClass(JSContext *cx, JSObject *obj)
1820
{
1860
{
1821
    JSObject *module = NewObjectWithClassProto(cx, &ProxyClass, NULL, obj);
1861
    JSObject *module = NewObjectWithClassProto(cx, &ProxyClass, NULL, obj);
1822
    if (!module || !module->setSingletonType(cx))
1862
    if (!module || !module->setSingletonType(cx))
1823
        return NULL;
1863
        return NULL;
(-)a/js/src/jsproxy.h (-12 / +19 lines)
Line     Link Here 
 Lines 166-220   inline bool IsFunctionProxy(const JSObje Link Here 
166
166
167
inline bool IsProxy(const JSObject *obj)
167
inline bool IsProxy(const JSObject *obj)
168
{
168
{
169
    Class *clasp = GetObjectClass(obj);
169
    Class *clasp = GetObjectClass(obj);
170
    return IsObjectProxyClass(clasp) || IsFunctionProxyClass(clasp);
170
    return IsObjectProxyClass(clasp) || IsFunctionProxyClass(clasp);
171
}
171
}
172
172
173
/* Shared between object and function proxies. */
173
/* Shared between object and function proxies. */
174
const uint32_t JSSLOT_PROXY_HANDLER = 0;
174
const uint32_t JSSLOT_PROXY_HANDLER       = 0;
175
const uint32_t JSSLOT_PROXY_PRIVATE = 1;
175
const uint32_t JSSLOT_PROXY_TARGET_VALUE  = 1;
176
const uint32_t JSSLOT_PROXY_EXTRA   = 2;
176
const uint32_t JSSLOT_PROXY_HANDLER_VALUE = 2;
177
const uint32_t JSSLOT_PROXY_EXTRA         = 3;
177
/* Function proxies only. */
178
/* Function proxies only. */
178
const uint32_t JSSLOT_PROXY_CALL = 4;
179
const uint32_t JSSLOT_PROXY_CALL = 4;
179
const uint32_t JSSLOT_PROXY_CONSTRUCT = 5;
180
const uint32_t JSSLOT_PROXY_CONSTRUCT = 5;
180
181
181
inline ProxyHandler *
182
inline ProxyHandler *
182
GetProxyHandler(const JSObject *obj)
183
GetProxyHandler(const JSObject *obj)
183
{
184
{
184
    JS_ASSERT(IsProxy(obj));
185
    JS_ASSERT(IsProxy(obj));
185
    return (ProxyHandler *) GetReservedSlot(obj, JSSLOT_PROXY_HANDLER).toPrivate();
186
    return (ProxyHandler *) GetReservedSlot(obj, JSSLOT_PROXY_HANDLER).toPrivate();
186
}
187
}
187
188
188
inline const Value &
189
inline const Value &
189
GetProxyPrivate(const JSObject *obj)
190
GetProxyTargetValue(const JSObject *obj)
190
{
191
{
191
    JS_ASSERT(IsProxy(obj));
192
    JS_ASSERT(IsProxy(obj));
192
    return GetReservedSlot(obj, JSSLOT_PROXY_PRIVATE);
193
    return GetReservedSlot(obj, JSSLOT_PROXY_TARGET_VALUE);
193
}
194
}
194
195
195
inline const Value &
196
inline const Value &
196
GetProxyExtra(const JSObject *obj, size_t n)
197
GetProxyHandlerValue(const JSObject *obj)
197
{
198
{
198
    JS_ASSERT(IsProxy(obj));
199
    JS_ASSERT(IsProxy(obj));
199
    return GetReservedSlot(obj, JSSLOT_PROXY_EXTRA + n);
200
    return GetReservedSlot(obj, JSSLOT_PROXY_HANDLER_VALUE);
201
}
202
203
inline const Value &
204
GetProxyExtra(const JSObject *obj)
205
{
206
    JS_ASSERT(IsProxy(obj));
207
    return GetReservedSlot(obj, JSSLOT_PROXY_EXTRA);
200
}
208
}
201
209
202
inline void
210
inline void
203
SetProxyExtra(JSObject *obj, size_t n, const Value &extra)
211
SetProxyExtra(JSObject *obj, const Value &extra)
204
{
212
{
205
    JS_ASSERT(IsProxy(obj));
213
    JS_ASSERT(IsProxy(obj));
206
    JS_ASSERT(n <= 1);
214
    SetReservedSlot(obj, JSSLOT_PROXY_EXTRA, extra);
207
    SetReservedSlot(obj, JSSLOT_PROXY_EXTRA + n, extra);
208
}
215
}
209
216
210
JS_FRIEND_API(JSObject *)
217
JS_FRIEND_API(JSObject *)
211
NewProxyObject(JSContext *cx, ProxyHandler *handler, const Value &priv,
218
NewProxyObject(JSContext *cx, ProxyHandler *handler, const Value &targetValue,
212
               JSObject *proto, JSObject *parent,
219
               const Value &handlerValue,  JSObject *proto, JSObject *parent,
213
               JSObject *call = NULL, JSObject *construct = NULL);
220
               JSObject *call = NULL, JSObject *construct = NULL);
214
221
215
} /* namespace js */
222
} /* namespace js */
216
223
217
JS_BEGIN_EXTERN_C
224
JS_BEGIN_EXTERN_C
218
225
219
extern JS_FRIEND_API(JSObject *)
226
extern JS_FRIEND_API(JSObject *)
220
js_InitProxyClass(JSContext *cx, JSObject *obj);
227
js_InitProxyClass(JSContext *cx, JSObject *obj);
(-)a/js/src/jswrapper.cpp (-5 / +5 lines)
Line     Link Here 
 Lines 72-88   Wrapper::getWrapperFamily() Link Here 
72
}
72
}
73
73
74
JS_FRIEND_API(JSObject *)
74
JS_FRIEND_API(JSObject *)
75
js::UnwrapObject(JSObject *wrapped, bool stopAtOuter, unsigned *flagsp)
75
js::UnwrapObject(JSObject *wrapped, bool stopAtOuter, unsigned *flagsp)
76
{
76
{
77
    unsigned flags = 0;
77
    unsigned flags = 0;
78
    while (wrapped->isWrapper()) {
78
    while (wrapped->isWrapper()) {
79
        flags |= static_cast<Wrapper *>(GetProxyHandler(wrapped))->flags();
79
        flags |= static_cast<Wrapper *>(GetProxyHandler(wrapped))->flags();
80
        wrapped = GetProxyPrivate(wrapped).toObjectOrNull();
80
        wrapped = GetProxyTargetValue(wrapped).toObjectOrNull();
81
        if (stopAtOuter && wrapped->getClass()->ext.innerObject)
81
        if (stopAtOuter && wrapped->getClass()->ext.innerObject)
82
            break;
82
            break;
83
    }
83
    }
84
    if (flagsp)
84
    if (flagsp)
85
        *flagsp = flags;
85
        *flagsp = flags;
86
    return wrapped;
86
    return wrapped;
87
}
87
}
88
88
 Lines 357-379   Wrapper::iteratorNext(JSContext *cx, JSO Link Here 
357
        vp->setMagic(JS_NO_ITER_VALUE);
357
        vp->setMagic(JS_NO_ITER_VALUE);
358
    }
358
    }
359
    return true;
359
    return true;
360
}
360
}
361
361
362
void
362
void
363
Wrapper::trace(JSTracer *trc, JSObject *wrapper)
363
Wrapper::trace(JSTracer *trc, JSObject *wrapper)
364
{
364
{
365
    MarkSlot(trc, &wrapper->getReservedSlotRef(JSSLOT_PROXY_PRIVATE), "wrappedObject");
365
    MarkSlot(trc, &wrapper->getReservedSlotRef(JSSLOT_PROXY_TARGET_VALUE), "wrappedObject");
366
}
366
}
367
367
368
JSObject *
368
JSObject *
369
Wrapper::wrappedObject(const JSObject *wrapper)
369
Wrapper::wrappedObject(const JSObject *wrapper)
370
{
370
{
371
    return GetProxyPrivate(wrapper).toObjectOrNull();
371
    return GetProxyTargetValue(wrapper).toObjectOrNull();
372
}
372
}
373
373
374
Wrapper *
374
Wrapper *
375
Wrapper::wrapperHandler(const JSObject *wrapper)
375
Wrapper::wrapperHandler(const JSObject *wrapper)
376
{
376
{
377
    return static_cast<Wrapper *>(GetProxyHandler(wrapper));
377
    return static_cast<Wrapper *>(GetProxyHandler(wrapper));
378
}
378
}
379
379
 Lines 394-410   Wrapper Wrapper::singleton((unsigned)0); Link Here 
394
JSObject *
394
JSObject *
395
Wrapper::New(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent, Wrapper *handler)
395
Wrapper::New(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent, Wrapper *handler)
396
{
396
{
397
    JS_ASSERT(parent);
397
    JS_ASSERT(parent);
398
    if (obj->isXML()) {
398
    if (obj->isXML()) {
399
        JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_WRAP_XML_OBJECT);
399
        JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_WRAP_XML_OBJECT);
400
        return NULL;
400
        return NULL;
401
    }
401
    }
402
    return NewProxyObject(cx, handler, ObjectValue(*obj), proto, parent,
402
    return NewProxyObject(cx, handler, ObjectValue(*obj), ObjectValue(*obj), proto, parent,
403
                          obj->isCallable() ? obj : NULL, NULL);
403
                          obj->isCallable() ? obj : NULL, NULL);
404
}
404
}
405
405
406
/* Compartments. */
406
/* Compartments. */
407
407
408
namespace js {
408
namespace js {
409
409
410
extern JSObject *
410
extern JSObject *
 Lines 865-881   CrossCompartmentWrapper::iteratorNext(JS Link Here 
865
           NOTHING,
865
           NOTHING,
866
           Wrapper::iteratorNext(cx, wrapper, vp),
866
           Wrapper::iteratorNext(cx, wrapper, vp),
867
           call.origin->wrap(cx, vp));
867
           call.origin->wrap(cx, vp));
868
}
868
}
869
869
870
void
870
void
871
CrossCompartmentWrapper::trace(JSTracer *trc, JSObject *wrapper)
871
CrossCompartmentWrapper::trace(JSTracer *trc, JSObject *wrapper)
872
{
872
{
873
    MarkCrossCompartmentSlot(trc, &wrapper->getReservedSlotRef(JSSLOT_PROXY_PRIVATE),
873
    MarkCrossCompartmentSlot(trc, &wrapper->getReservedSlotRef(JSSLOT_PROXY_TARGET_VALUE),
874
                             "wrappedObject");
874
                             "wrappedObject");
875
}
875
}
876
876
877
CrossCompartmentWrapper CrossCompartmentWrapper::singleton(0u);
877
CrossCompartmentWrapper CrossCompartmentWrapper::singleton(0u);
878
878
879
/* Security wrappers. */
879
/* Security wrappers. */
880
880
881
template <class Base>
881
template <class Base>
(-)a/js/src/vm/Debugger.cpp (-2 / +2 lines)
Line     Link Here 
 Lines 1752-1768   Debugger::unwrapDebuggeeArgument(JSConte Link Here 
1752
    if (obj) {
1752
    if (obj) {
1753
        if (obj->getClass() == &DebuggerObject_class) {
1753
        if (obj->getClass() == &DebuggerObject_class) {
1754
            Value rv = v;
1754
            Value rv = v;
1755
            if (!unwrapDebuggeeValue(cx, &rv))
1755
            if (!unwrapDebuggeeValue(cx, &rv))
1756
                return NULL;
1756
                return NULL;
1757
            return &rv.toObject();
1757
            return &rv.toObject();
1758
        }
1758
        }
1759
        if (IsCrossCompartmentWrapper(obj))
1759
        if (IsCrossCompartmentWrapper(obj))
1760
            return &GetProxyPrivate(obj).toObject();
1760
            return &GetProxyTargetValue(obj).toObject();
1761
    }
1761
    }
1762
    return obj;
1762
    return obj;
1763
}
1763
}
1764
1764
1765
JSBool
1765
JSBool
1766
Debugger::addDebuggee(JSContext *cx, unsigned argc, Value *vp)
1766
Debugger::addDebuggee(JSContext *cx, unsigned argc, Value *vp)
1767
{
1767
{
1768
    REQUIRE_ARGC("Debugger.addDebuggee", 1);
1768
    REQUIRE_ARGC("Debugger.addDebuggee", 1);
 Lines 1894-1910   Debugger::construct(JSContext *cx, unsig Link Here 
1894
    obj->setPrivate(dbg);
1894
    obj->setPrivate(dbg);
1895
    if (!dbg->init(cx)) {
1895
    if (!dbg->init(cx)) {
1896
        cx->delete_(dbg);
1896
        cx->delete_(dbg);
1897
        return false;
1897
        return false;
1898
    }
1898
    }
1899
1899
1900
    /* Add the initial debuggees, if any. */
1900
    /* Add the initial debuggees, if any. */
1901
    for (unsigned i = 0; i < argc; i++) {
1901
    for (unsigned i = 0; i < argc; i++) {
1902
        GlobalObject *debuggee = &GetProxyPrivate(&args[i].toObject()).toObject().global();
1902
        GlobalObject *debuggee = &GetProxyHandlerValue(&args[i].toObject()).toObject().global();
1903
        if (!dbg->addDebuggeeGlobal(cx, debuggee))
1903
        if (!dbg->addDebuggeeGlobal(cx, debuggee))
1904
            return false;
1904
            return false;
1905
    }
1905
    }
1906
1906
1907
    args.rval().setObject(*obj);
1907
    args.rval().setObject(*obj);
1908
    return true;
1908
    return true;
1909
}
1909
}
1910
1910

Return to bug 703537