| Differences between
and this patch
- Source/JavaScriptCore/ChangeLog +20 lines
Lines 1-3 Source/JavaScriptCore/ChangeLog_sec1
1
2016-02-18  Saam Barati  <sbarati@apple.com>
2
3
        Follow up fix to Implement Proxy.[[GetOwnProperty]]
4
        https://bugs.webkit.org/show_bug.cgi?id=154314
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Part of the implementation was broken because
9
        of how JSObject::getOwnPropertyDescriptor worked.
10
        I've fixed JSObject::getOwnPropertyDescriptor to
11
        be able to handle ProxyObject.
12
13
        * runtime/JSObject.cpp:
14
        (JSC::JSObject::getOwnPropertyDescriptor):
15
        * runtime/ProxyObject.cpp:
16
        (JSC::ProxyObject::performInternalMethodGetOwnProperty):
17
        * tests/stress/proxy-get-own-property.js:
18
        (assert):
19
        (assert.let.handler.get getOwnPropertyDescriptor):
20
1
2016-02-18  Saam Barati  <sbarati@apple.com>
21
2016-02-18  Saam Barati  <sbarati@apple.com>
2
22
3
        Implement Proxy.[[GetOwnProperty]]
23
        Implement Proxy.[[GetOwnProperty]]
- Source/JavaScriptCore/runtime/JSObject.cpp -3 / +8 lines
Lines 46-51 Source/JavaScriptCore/runtime/JSObject.cpp_sec1
46
#include "JSCInlines.h"
46
#include "JSCInlines.h"
47
#include "PropertyDescriptor.h"
47
#include "PropertyDescriptor.h"
48
#include "PropertyNameArray.h"
48
#include "PropertyNameArray.h"
49
#include "ProxyObject.h"
49
#include "Reject.h"
50
#include "Reject.h"
50
#include "SlotVisitorInlines.h"
51
#include "SlotVisitorInlines.h"
51
#include <math.h>
52
#include <math.h>
Lines 2560-2568 bool JSObject::getOwnPropertyDescriptor( Source/JavaScriptCore/runtime/JSObject.cpp_sec2
2560
    // but getOwnPropertyDescriptor() should only work for 'own' properties so we exit early if we detect that
2561
    // but getOwnPropertyDescriptor() should only work for 'own' properties so we exit early if we detect that
2561
    // the property is not an own property.
2562
    // the property is not an own property.
2562
    if (slot.slotBase() != this && slot.slotBase()) {
2563
    if (slot.slotBase() != this && slot.slotBase()) {
2563
        auto* proxy = jsDynamicCast<JSProxy*>(this);
2564
        JSProxy* jsProxy = jsDynamicCast<JSProxy*>(this);
2564
        if (!proxy || proxy->target() != slot.slotBase())
2565
        if (!jsProxy || jsProxy->target() != slot.slotBase()) {
2565
            return false;
2566
            // Try ProxyObject.
2567
            ProxyObject* proxyObject = jsDynamicCast<ProxyObject*>(this);
2568
            if (!proxyObject || proxyObject->target() != slot.slotBase())
2569
                return false;
2570
        }
2566
    }
2571
    }
2567
2572
2568
    if (slot.isAccessor())
2573
    if (slot.isAccessor())
- Source/JavaScriptCore/runtime/ProxyObject.cpp +2 lines
Lines 143-148 bool ProxyObject::performInternalMethodG Source/JavaScriptCore/runtime/ProxyObject.cpp_sec1
143
    CallData callData;
143
    CallData callData;
144
    CallType callType;
144
    CallType callType;
145
    JSValue getOwnPropertyDescriptorMethod = handler->getMethod(exec, callData, callType, makeIdentifier(vm, "getOwnPropertyDescriptor"), ASCIILiteral("'getOwnPropertyDescriptor' property of a Proxy's handler should be callable."));
145
    JSValue getOwnPropertyDescriptorMethod = handler->getMethod(exec, callData, callType, makeIdentifier(vm, "getOwnPropertyDescriptor"), ASCIILiteral("'getOwnPropertyDescriptor' property of a Proxy's handler should be callable."));
146
    if (exec->hadException())
147
        return false;
146
    JSObject* target = this->target();
148
    JSObject* target = this->target();
147
    if (getOwnPropertyDescriptorMethod.isUndefined())
149
    if (getOwnPropertyDescriptorMethod.isUndefined())
148
        return target->methodTable(vm)->getOwnPropertySlot(target, exec, propertyName, slot);
150
        return target->methodTable(vm)->getOwnPropertySlot(target, exec, propertyName, slot);
- Source/JavaScriptCore/tests/stress/proxy-get-own-property.js +24 lines
Lines 186-188 function assert(b) { Source/JavaScriptCore/tests/stress/proxy-get-own-property.js_sec1
186
        assert(pDesc.enumerable === true);
186
        assert(pDesc.enumerable === true);
187
    }
187
    }
188
}
188
}
189
190
{
191
    let target = {};
192
    let error = null;
193
    let handler = { get getOwnPropertyDescriptor() {
194
        error = new Error("blah");
195
        throw error;
196
    }};
197
    Object.defineProperty(target, "x", {
198
        enumerable: true,
199
        configurable: false
200
    });
201
    let proxy = new Proxy(target, handler);
202
    for (let i = 0; i < 500; i++) {
203
        let threw = false;
204
        try {
205
            let pDesc = Object.getOwnPropertyDescriptor(proxy, "x");
206
        } catch(e) {
207
            threw = true;
208
            assert(e === error);
209
        }
210
        assert(threw);
211
    }
212
}

Return to Bug 154314