Changeset 213453 in webkit


Ignore:
Timestamp:
Mar 6, 2017 9:26:35 AM (7 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Allow indexed module namespace object fields
https://bugs.webkit.org/show_bug.cgi?id=168870

Reviewed by Saam Barati.

JSTests:

  • wasm/spec-tests/names.wast.js:

Source/JavaScriptCore:

While JS modules cannot expose any indexed bindings,
Wasm modules can expose them. However, module namespace
object currently does not support indexed properties.
This patch allows module namespace objects to offer
indexed binding accesses.

  • runtime/JSModuleNamespaceObject.cpp:

(JSC::JSModuleNamespaceObject::getOwnPropertySlotCommon):
(JSC::JSModuleNamespaceObject::getOwnPropertySlot):
(JSC::JSModuleNamespaceObject::getOwnPropertySlotByIndex):

  • runtime/JSModuleNamespaceObject.h:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r213452 r213453  
     12017-03-06  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Allow indexed module namespace object fields
     4        https://bugs.webkit.org/show_bug.cgi?id=168870
     5
     6        Reviewed by Saam Barati.
     7
     8        * wasm/spec-tests/names.wast.js:
     9
    1102017-03-06  Yusuke Suzuki  <utatane.tea@gmail.com>
    211
  • trunk/JSTests/wasm/spec-tests/names.wast.js

    r213067 r213453  
    103103assert_return(() => $$.exports["__malloc"](), f32(6.3125));
    104104assert_return(() => $$.exports["~!@#$%^&*()_+`-={}|[]\x5c:\x22;'<>?,./ "](), f32(6.34375));
    105 // FIXME exporting a property with a name that's a number doesn't work https://bugs.webkit.org/show_bug.cgi?id=168857
    106 //assert_return(() => $$.exports["0"](), f32(6.359375));
     105assert_return(() => $$.exports["0"](), f32(6.359375));
    107106assert_return(() => $$.exports["_"](), f32(6.375));
    108107assert_return(() => $$.exports["$"](), f32(6.390625));
  • trunk/Source/JavaScriptCore/ChangeLog

    r213452 r213453  
     12017-03-06  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Allow indexed module namespace object fields
     4        https://bugs.webkit.org/show_bug.cgi?id=168870
     5
     6        Reviewed by Saam Barati.
     7
     8        While JS modules cannot expose any indexed bindings,
     9        Wasm modules can expose them. However, module namespace
     10        object currently does not support indexed properties.
     11        This patch allows module namespace objects to offer
     12        indexed binding accesses.
     13
     14        * runtime/JSModuleNamespaceObject.cpp:
     15        (JSC::JSModuleNamespaceObject::getOwnPropertySlotCommon):
     16        (JSC::JSModuleNamespaceObject::getOwnPropertySlot):
     17        (JSC::JSModuleNamespaceObject::getOwnPropertySlotByIndex):
     18        * runtime/JSModuleNamespaceObject.h:
     19
    1202017-03-06  Yusuke Suzuki  <utatane.tea@gmail.com>
    221
  • trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp

    r212818 r213453  
    114114}
    115115
    116 bool JSModuleNamespaceObject::getOwnPropertySlot(JSObject* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
     116bool JSModuleNamespaceObject::getOwnPropertySlotCommon(ExecState* exec, PropertyName propertyName, PropertySlot& slot)
    117117{
    118118    VM& vm = exec->vm();
     
    120120
    121121    // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-getownproperty-p
    122 
    123     JSModuleNamespaceObject* thisObject = jsCast<JSModuleNamespaceObject*>(cell);
    124122
    125123    // step 1.
     
    127125    // It may return the descriptor with writable: true, but namespace objects does not allow it in [[Set]] / [[DefineOwnProperty]] side.
    128126    if (propertyName.isSymbol())
    129         return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot);
     127        return JSObject::getOwnPropertySlot(this, exec, propertyName, slot);
    130128
    131129    slot.setIsTaintedByOpaqueObject();
    132130
    133     auto iterator = thisObject->m_exports.find(propertyName.uid());
    134     if (iterator == thisObject->m_exports.end())
     131    auto iterator = m_exports.find(propertyName.uid());
     132    if (iterator == m_exports.end())
    135133        return false;
    136134    ExportEntry& exportEntry = iterator->value;
     
    139137    case PropertySlot::InternalMethodType::GetOwnProperty:
    140138    case PropertySlot::InternalMethodType::Get: {
    141         JSModuleEnvironment* environment = thisObject->moduleRecordAt(exportEntry.moduleRecordOffset)->moduleEnvironment();
     139        JSModuleEnvironment* environment = moduleRecordAt(exportEntry.moduleRecordOffset)->moduleEnvironment();
    142140        ScopeOffset scopeOffset;
    143141        JSValue value = getValue(environment, exportEntry.localName, scopeOffset);
     
    148146        }
    149147
    150         slot.setValueModuleNamespace(thisObject, DontDelete, value, environment, scopeOffset);
     148        slot.setValueModuleNamespace(this, DontDelete, value, environment, scopeOffset);
    151149        return true;
    152150    }
     
    156154        // [[Get]] / [[GetOwnProperty]] onto namespace object could throw an error while [[HasProperty]] just returns true here.
    157155        // https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects-hasproperty-p
    158         slot.setValue(thisObject, DontDelete, jsUndefined());
     156        slot.setValue(this, DontDelete, jsUndefined());
    159157        return true;
    160158    }
     
    166164    RELEASE_ASSERT_NOT_REACHED();
    167165    return false;
     166}
     167
     168bool JSModuleNamespaceObject::getOwnPropertySlot(JSObject* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
     169{
     170    JSModuleNamespaceObject* thisObject = jsCast<JSModuleNamespaceObject*>(cell);
     171    return thisObject->getOwnPropertySlotCommon(exec, propertyName, slot);
     172}
     173
     174bool JSModuleNamespaceObject::getOwnPropertySlotByIndex(JSObject* cell, ExecState* exec, unsigned propertyName, PropertySlot& slot)
     175{
     176    JSModuleNamespaceObject* thisObject = jsCast<JSModuleNamespaceObject*>(cell);
     177    return thisObject->getOwnPropertySlotCommon(exec, Identifier::from(exec, propertyName), slot);
    168178}
    169179
  • trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.h

    r212818 r213453  
    4949
    5050    JS_EXPORT_PRIVATE static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
     51    JS_EXPORT_PRIVATE static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned propertyName, PropertySlot&);
    5152    JS_EXPORT_PRIVATE static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
    5253    JS_EXPORT_PRIVATE static bool putByIndex(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
     
    7172    static void destroy(JSCell*);
    7273    static void visitChildren(JSCell*, SlotVisitor&);
     74    bool getOwnPropertySlotCommon(ExecState*, PropertyName, PropertySlot&);
    7375
    7476    WriteBarrierBase<AbstractModuleRecord>& moduleRecordAt(unsigned offset)
Note: See TracChangeset for help on using the changeset viewer.