Ignore:
Timestamp:
Feb 25, 2016, 2:58:23 PM (9 years ago)
Author:
[email protected]
Message:

[ES6] Implement Proxy.Set
https://bugs.webkit.org/show_bug.cgi?id=154511

Reviewed by Filip Pizlo.

This patch is mostly an implementation of
Proxy.Set with respect to section 9.5.9
of the ECMAScript spec.
https://tc39.github.io/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver

This patch also changes JSObject::putInline and JSObject::putByIndex
to be aware that a Proxy in the prototype chain will intercept
property accesses.

  • runtime/JSObject.cpp:

(JSC::JSObject::putInlineSlow):
(JSC::JSObject::attemptToInterceptPutByIndexOnHoleForPrototype):

  • runtime/JSObject.h:
  • runtime/JSObjectInlines.h:

(JSC::JSObject::canPerformFastPutInline):
(JSC::JSObject::putInline):

  • runtime/JSType.h:
  • runtime/ProxyObject.cpp:

(JSC::ProxyObject::getOwnPropertySlotByIndex):
(JSC::ProxyObject::performPut):
(JSC::ProxyObject::put):
(JSC::ProxyObject::putByIndexCommon):
(JSC::ProxyObject::putByIndex):
(JSC::performProxyCall):
(JSC::ProxyObject::getCallData):
(JSC::performProxyConstruct):
(JSC::ProxyObject::deletePropertyByIndex):
(JSC::ProxyObject::visitChildren):

  • runtime/ProxyObject.h:

(JSC::ProxyObject::create):
(JSC::ProxyObject::createStructure):
(JSC::ProxyObject::target):
(JSC::ProxyObject::handler):

  • tests/es6.yaml:
  • tests/stress/proxy-set.js: Added.

(assert):
(throw.new.Error.let.handler.set 45):
(throw.new.Error):
(let.target.set x):
(let.target.get x):
(set let):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSObjectInlines.h

    r194175 r197136  
    3131namespace JSC {
    3232
     33ALWAYS_INLINE bool JSObject::canPerformFastPutInline(ExecState* exec, VM& vm, PropertyName propertyName)
     34{
     35    if (UNLIKELY(propertyName == exec->propertyNames().underscoreProto))
     36        return false;
     37
     38    // Check if there are any setters or getters in the prototype chain
     39    JSValue prototype;
     40    JSObject* obj = this;
     41    while (true) {
     42        if (obj->structure(vm)->hasReadOnlyOrGetterSetterPropertiesExcludingProto() || obj->type() == ProxyObjectType)
     43            return false;
     44
     45        prototype = obj->prototype();
     46        if (prototype.isNull())
     47            return true;
     48
     49        obj = asObject(prototype);
     50    }
     51
     52    ASSERT_NOT_REACHED();
     53}
     54
    3355// ECMA 8.6.2.2
    3456ALWAYS_INLINE void JSObject::putInline(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
     
    4567        return;
    4668    }
    47    
    48     // Check if there are any setters or getters in the prototype chain
    49     JSValue prototype;
    50     if (propertyName != exec->propertyNames().underscoreProto) {
    51         for (JSObject* obj = thisObject; !obj->structure(vm)->hasReadOnlyOrGetterSetterPropertiesExcludingProto(); obj = asObject(prototype)) {
    52             prototype = obj->prototype();
    53             if (prototype.isNull()) {
    54                 ASSERT(!thisObject->structure(vm)->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName));
    55                 if (!thisObject->putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot)
    56                     && slot.isStrictMode())
    57                     throwTypeError(exec, ASCIILiteral(StrictModeReadonlyPropertyWriteError));
    58                 return;
    59             }
    60         }
    61     }
    6269
    63     thisObject->putInlineSlow(exec, propertyName, value, slot);
     70    if (thisObject->canPerformFastPutInline(exec, vm, propertyName)) {
     71        ASSERT(!thisObject->structure(vm)->prototypeChainMayInterceptStoreTo(exec->vm(), propertyName));
     72        if (!thisObject->putDirectInternal<PutModePut>(vm, propertyName, value, 0, slot)
     73            && slot.isStrictMode())
     74            throwTypeError(exec, ASCIILiteral(StrictModeReadonlyPropertyWriteError));
     75    } else
     76        thisObject->putInlineSlow(exec, propertyName, value, slot);
    6477}
    6578
Note: See TracChangeset for help on using the changeset viewer.