Changeset 252191 in webkit


Ignore:
Timestamp:
Nov 7, 2019 10:31:31 AM (4 years ago)
Author:
commit-queue@webkit.org
Message:

HasProperty? result of Proxy in prototype chain is ignored
https://bugs.webkit.org/show_bug.cgi?id=203560

Patch by Alexey Shvayka <Alexey Shvayka> on 2019-11-07
Reviewed by Ross Kirsling.

JSTests:

  • stress/proxy-get-prototype-of.js: Correct Proxy "has" trap test.
  • test262/expectations.yaml: Mark 6 test cases as passing.

Source/JavaScriptCore:

Before this change, when HasProperty? was called on ordinary object with Proxy in prototype chain,
falsy result of Proxy's "has" trap was ignored and prototype chain was inspected further.

According to spec, OrdinaryHasProperty unconditionally returns result of parent's HasProperty? call.
(step 5.a of https://tc39.es/ecma262/#sec-ordinaryhasproperty)

  • runtime/JSObjectInlines.h:

(JSC::JSObject::getPropertySlot):
(JSC::JSObject::getNonIndexPropertySlot):

  • runtime/ProxyObject.cpp:

(JSC::ProxyObject::performHasProperty): Walk the prototype chain in performDefaultHasProperty.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r252160 r252191  
     12019-11-07  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        [[HasProperty]] result of Proxy in prototype chain is ignored
     4        https://bugs.webkit.org/show_bug.cgi?id=203560
     5
     6        Reviewed by Ross Kirsling.
     7
     8        * stress/proxy-get-prototype-of.js: Correct Proxy "has" trap test.
     9        * test262/expectations.yaml: Mark 6 test cases as passing.
     10
    1112019-11-06  Mark Lam  <mark.lam@apple.com>
    212
  • trunk/JSTests/stress/proxy-get-prototype-of.js

    r252158 r252191  
    390390    let handler = {
    391391        getPrototypeOf: function(theTarget) {
    392             assert(theTarget === target);
    393392            called = true;
    394393            return proto;
     
    401400    let proxy = new Proxy(target, handler);
    402401    for (let i = 0; i < 500; i++) {
    403         let result = "x" in proxy;
    404         assert(called);
    405         called = false;
     402        let result = 1 in proxy;
     403        assert(!called);
    406404    }
    407405}
  • trunk/JSTests/test262/expectations.yaml

    r252158 r252191  
    634634  default: 'TypeError: Attempted to assign to readonly property.'
    635635  strict mode: 'TypeError: Attempted to assign to readonly property.'
    636 test/built-ins/Array/prototype/indexOf/calls-only-has-on-prototype-after-length-zeroed.js:
    637   default: 'Test262Error: [[GetPrototypeOf]] trap called'
    638   strict mode: 'Test262Error: [[GetPrototypeOf]] trap called'
    639 test/built-ins/Array/prototype/lastIndexOf/calls-only-has-on-prototype-after-length-zeroed.js:
    640   default: 'Test262Error: [[GetPrototypeOf]] trap called'
    641   strict mode: 'Test262Error: [[GetPrototypeOf]] trap called'
    642636test/built-ins/Array/prototype/map/target-array-with-non-writable-property.js:
    643637  default: 'TypeError: Attempted to assign to readonly property.'
     
    665659  strict mode: 'Test262Error: Length is 2**53 - 1 Expected a TypeError to be thrown but no exception was thrown at all'
    666660test/built-ins/Array/prototype/reverse/length-exceeding-integer-limit-with-proxy.js:
    667   default: 'Test262Error: Expected a StopReverse but got a Test262Error'
    668   strict mode: 'Test262Error: Expected a StopReverse but got a Test262Error'
     661  default: 'Test262Error: Expected [Get:length, Has:0, Get:0, Has:4294967294, Delete:0, Set:4294967294, GetOwnPropertyDescriptor:4294967294, DefineProperty:4294967294, Has:1, Has:4294967293, Delete:1, Delete:4294967293, Has:2, Get:2, Has:4294967292, Delete:2, Set:4294967292, GetOwnPropertyDescriptor:4294967292, DefineProperty:4294967292, Has:3, Has:4294967291, Delete:3, Delete:4294967291, Has:4, Get:4] and [Get:length, Has:0, Get:0, Has:9007199254740990, Get:9007199254740990, Set:0, GetOwnPropertyDescriptor:0, DefineProperty:0, Set:9007199254740990, GetOwnPropertyDescriptor:9007199254740990, DefineProperty:9007199254740990, Has:1, Has:9007199254740989, Has:2, Get:2, Has:9007199254740988, Delete:2, Set:9007199254740988, GetOwnPropertyDescriptor:9007199254740988, DefineProperty:9007199254740988, Has:3, Has:9007199254740987, Get:9007199254740987, Set:3, GetOwnPropertyDescriptor:3, DefineProperty:3, Delete:9007199254740987, Has:4, Get:4] to have the same contents. '
     662  strict mode: 'Test262Error: Expected [Get:length, Has:0, Get:0, Has:4294967294, Delete:0, Set:4294967294, GetOwnPropertyDescriptor:4294967294, DefineProperty:4294967294, Has:1, Has:4294967293, Delete:1, Delete:4294967293, Has:2, Get:2, Has:4294967292, Delete:2, Set:4294967292, GetOwnPropertyDescriptor:4294967292, DefineProperty:4294967292, Has:3, Has:4294967291, Delete:3, Delete:4294967291, Has:4, Get:4] and [Get:length, Has:0, Get:0, Has:9007199254740990, Get:9007199254740990, Set:0, GetOwnPropertyDescriptor:0, DefineProperty:0, Set:9007199254740990, GetOwnPropertyDescriptor:9007199254740990, DefineProperty:9007199254740990, Has:1, Has:9007199254740989, Has:2, Get:2, Has:9007199254740988, Delete:2, Set:9007199254740988, GetOwnPropertyDescriptor:9007199254740988, DefineProperty:9007199254740988, Has:3, Has:9007199254740987, Get:9007199254740987, Set:3, GetOwnPropertyDescriptor:3, DefineProperty:3, Delete:9007199254740987, Has:4, Get:4] to have the same contents. '
    669663test/built-ins/Array/prototype/slice/length-exceeding-integer-limit-proxied-array.js:
    670664  default: 'Test262Error: Expected [] and [9007199254740989, 9007199254740990] to have the same contents. slice(9007199254740989)'
     
    686680  strict mode: 'TypeError: Attempted to assign to readonly property.'
    687681test/built-ins/Array/prototype/splice/create-species-length-exceeding-integer-limit.js:
    688   default: 'Test262Error: Expected a StopSplice but got a Test262Error'
    689   strict mode: 'Test262Error: Expected a StopSplice but got a Test262Error'
     682  default: 'Test262Error: length and deleteCount were correctly clamped to 2^53-1 Expected SameValue(«4294967295», «9007199254740991») to be true'
     683  strict mode: 'Test262Error: length and deleteCount were correctly clamped to 2^53-1 Expected SameValue(«4294967295», «9007199254740991») to be true'
    690684test/built-ins/Array/prototype/splice/length-and-deleteCount-exceeding-integer-limit.js:
    691685  default: "Test262Error: Expected [] and [9007199254740989, 9007199254740990] to have the same contents. arrayLike['9007199254740989'] and arrayLike['9007199254740990'] are removed"
     
    11541148  default: 'Test262Error: Expected a TypeError but got a TypeError'
    11551149  strict mode: 'Test262Error: Expected a TypeError but got a TypeError'
    1156 test/built-ins/Proxy/has/call-in-prototype.js:
    1157   default: 'Test262Error: [[GetPrototypeOf]] trap called'
    1158   strict mode: 'Test262Error: [[GetPrototypeOf]] trap called'
    11591150test/built-ins/Proxy/revocable/revocation-function-name.js:
    11601151  default: 'Test262Error: obj should have an own property name'
  • trunk/Source/JavaScriptCore/ChangeLog

    r252177 r252191  
     12019-11-07  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        [[HasProperty]] result of Proxy in prototype chain is ignored
     4        https://bugs.webkit.org/show_bug.cgi?id=203560
     5
     6        Reviewed by Ross Kirsling.
     7
     8        Before this change, when [[HasProperty]] was called on ordinary object with Proxy in prototype chain,
     9        falsy result of Proxy's "has" trap was ignored and prototype chain was inspected further.
     10
     11        According to spec, OrdinaryHasProperty unconditionally returns result of parent's [[HasProperty]] call.
     12        (step 5.a of https://tc39.es/ecma262/#sec-ordinaryhasproperty)
     13
     14        * runtime/JSObjectInlines.h:
     15        (JSC::JSObject::getPropertySlot):
     16        (JSC::JSObject::getNonIndexPropertySlot):
     17        * runtime/ProxyObject.cpp:
     18        (JSC::ProxyObject::performHasProperty): Walk the prototype chain in performDefaultHasProperty.
     19
    1202019-11-06  Mark Lam  <mark.lam@apple.com>
    221
  • trunk/Source/JavaScriptCore/runtime/JSObjectInlines.h

    r252158 r252191  
    127127        if (hasSlot)
    128128            return true;
     129        if (object->type() == ProxyObjectType && slot.internalMethodType() == PropertySlot::InternalMethodType::HasProperty)
     130            return false;
    129131        JSValue prototype;
    130132        if (LIKELY(structure->classInfo()->methodTable.getPrototype == defaultGetPrototype || slot.internalMethodType() == PropertySlot::InternalMethodType::VMInquiry))
     
    160162            if (hasSlot)
    161163                return true;
     164            if (object->type() == ProxyObjectType && slot.internalMethodType() == PropertySlot::InternalMethodType::HasProperty)
     165                return false;
    162166        }
    163167        JSValue prototype;
  • trunk/Source/JavaScriptCore/runtime/ProxyObject.cpp

    r251425 r252191  
    323323
    324324    auto performDefaultHasProperty = [&] {
    325         return target->methodTable(vm)->getOwnPropertySlot(target, globalObject, propertyName, slot);
     325        return target->getPropertySlot(globalObject, propertyName, slot);
    326326    };
    327327
Note: See TracChangeset for help on using the changeset viewer.