Changeset 204248 in webkit for trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp
- Timestamp:
- Aug 7, 2016, 7:48:56 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp
r204160 r204248 99 99 } 100 100 101 static EncodedJSValue callbackGetter(ExecState* exec, EncodedJSValue thisValue, PropertyName propertyName)102 {103 JSModuleNamespaceObject* thisObject = jsCast<JSModuleNamespaceObject*>(JSValue::decode(thisValue));104 JSModuleRecord* moduleRecord = thisObject->moduleRecord();105 106 JSModuleRecord::Resolution resolution = moduleRecord->resolveExport(exec, Identifier::fromUid(exec, propertyName.uid()));107 ASSERT(resolution.type != JSModuleRecord::Resolution::Type::NotFound && resolution.type != JSModuleRecord::Resolution::Type::Ambiguous);108 109 JSModuleRecord* targetModule = resolution.moduleRecord;110 JSModuleEnvironment* targetEnvironment = targetModule->moduleEnvironment();111 112 PropertySlot trampolineSlot(targetEnvironment, PropertySlot::InternalMethodType::Get);113 if (!targetEnvironment->methodTable(exec->vm())->getOwnPropertySlot(targetEnvironment, exec, resolution.localName, trampolineSlot))114 return JSValue::encode(jsUndefined());115 116 JSValue value = trampolineSlot.getValue(exec, propertyName);117 if (exec->hadException())118 return JSValue::encode(jsUndefined());119 120 // If the value is filled with TDZ value, throw a reference error.121 if (!value)122 return throwVMError(exec, createTDZError(exec));123 return JSValue::encode(value);124 }125 126 101 bool JSModuleNamespaceObject::getOwnPropertySlot(JSObject* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot) 127 102 { … … 136 111 return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot); 137 112 113 // FIXME: Add IC for module namespace object. 114 // https://bugs.webkit.org/show_bug.cgi?id=160590 115 slot.disableCaching(); 116 slot.setIsTaintedByOpaqueObject(); 138 117 if (!thisObject->m_exports.contains(propertyName.uid())) 139 118 return false; 140 119 141 // https://esdiscuss.org/topic/march-24-meeting-notes 142 // http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-getownproperty-p 143 // section 9.4.6.5, step 6. 144 // This property will be seen as writable: true, enumerable:true, configurable: false. 145 // But this does not mean that this property is writable by users. 146 // 147 // In JSC, getOwnPropertySlot is not designed to throw any errors. But looking up the value from the module 148 // environment may throw error if the loaded variable is the TDZ value. To workaround, we set the custom 149 // getter function. When it is called, it looks up the variable and throws an error if the variable is not 150 // initialized. 151 slot.setCustom(thisObject, DontDelete, callbackGetter); 152 return true; 120 switch (slot.internalMethodType()) { 121 case PropertySlot::InternalMethodType::Get: 122 case PropertySlot::InternalMethodType::GetOwnProperty: { 123 JSModuleRecord* moduleRecord = thisObject->moduleRecord(); 124 125 JSModuleRecord::Resolution resolution = moduleRecord->resolveExport(exec, Identifier::fromUid(exec, propertyName.uid())); 126 ASSERT(resolution.type != JSModuleRecord::Resolution::Type::NotFound && resolution.type != JSModuleRecord::Resolution::Type::Ambiguous); 127 128 JSModuleRecord* targetModule = resolution.moduleRecord; 129 JSModuleEnvironment* targetEnvironment = targetModule->moduleEnvironment(); 130 131 PropertySlot trampolineSlot(targetEnvironment, PropertySlot::InternalMethodType::Get); 132 bool found = targetEnvironment->methodTable(exec->vm())->getOwnPropertySlot(targetEnvironment, exec, resolution.localName, trampolineSlot); 133 ASSERT_UNUSED(found, found); 134 135 JSValue value = trampolineSlot.getValue(exec, propertyName); 136 ASSERT(!exec->hadException()); 137 138 // If the value is filled with TDZ value, throw a reference error. 139 if (!value) { 140 throwVMError(exec, createTDZError(exec)); 141 return false; 142 } 143 144 slot.setValue(thisObject, DontDelete, value); 145 return true; 146 } 147 case PropertySlot::InternalMethodType::HasProperty: { 148 // Do not perform [[Get]] for [[HasProperty]]. 149 // [[Get]] / [[GetOwnProperty]] onto namespace object could throw an error while [[HasProperty]] just returns true here. 150 // https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects-hasproperty-p 151 slot.setValue(thisObject, DontDelete, jsUndefined()); 152 return true; 153 } 154 155 case PropertySlot::InternalMethodType::VMInquiry: 156 return false; 157 } 158 159 RELEASE_ASSERT_NOT_REACHED(); 160 return false; 153 161 } 154 162
Note:
See TracChangeset
for help on using the changeset viewer.