Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
[JSC] Update module namespace object according to the latest ECMA262
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=168280

Reviewed by Saam Barati.

JSTests:

* modules/namespace-object-symbol-iterator-name.js:
* modules/namespace-object-typed-array-fast-path.js:
* modules/namespace.js:
(shouldBe.JSON.stringify.Reflect.getOwnPropertyDescriptor):
(shouldThrow):

Source/JavaScriptCore:

Reflect updates to the module namespace object.

1. @@iterator property is dropped[1].
2. @@toStringTag property becomes non-configurable[1].
3. delete with Symbol should be delegated to the JSObject's one[2].

[1]: https://tc39.github.io/ecma262/#sec-module-namespace-objects
[2]: tc39/ecma262#767

* runtime/JSModuleNamespaceObject.cpp:
(JSC::JSModuleNamespaceObject::finishCreation):
(JSC::JSModuleNamespaceObject::deleteProperty):
(JSC::moduleNamespaceObjectSymbolIterator): Deleted.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@212430 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
[email protected] committed Feb 16, 2017
1 parent 19b9378 commit 920bd4c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 35 deletions.
13 changes: 13 additions & 0 deletions JSTests/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
2017-02-16 Yusuke Suzuki <[email protected]>

[JSC] Update module namespace object according to the latest ECMA262
https://bugs.webkit.org/show_bug.cgi?id=168280

Reviewed by Saam Barati.

* modules/namespace-object-symbol-iterator-name.js:
* modules/namespace-object-typed-array-fast-path.js:
* modules/namespace.js:
(shouldBe.JSON.stringify.Reflect.getOwnPropertyDescriptor):
(shouldThrow):

2017-02-11 Yusuke Suzuki <[email protected]>

[JSC] Implement (Shared)ArrayBuffer.prototype.byteLength
Expand Down
2 changes: 1 addition & 1 deletion JSTests/modules/namespace-object-symbol-iterator-name.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { shouldBe } from "./resources/assert.js";
import * as ns from "./namespace-object-symbol-iterator-name.js";

shouldBe(ns[Symbol.iterator].name, "[Symbol.iterator]");
shouldBe(ns[Symbol.iterator], undefined);
2 changes: 1 addition & 1 deletion JSTests/modules/namespace-object-typed-array-fast-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export let length = 42;
export let hello = 44;

let array = new Uint8Array(ns);
shouldBe(array.length, 2);
shouldBe(array.length, 0);
19 changes: 6 additions & 13 deletions JSTests/modules/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ shouldBe('Cappuccino' in namespace, true);
shouldBe('Matcha' in namespace, true);
shouldBe('Mocha' in namespace, true);
shouldBe('default' in namespace, true);
shouldBe(Symbol.iterator in namespace, true);
shouldBe(Symbol.iterator in namespace, false);
shouldBe('Tea' in namespace, false);

shouldBe(namespace.__proto__, undefined);
Expand Down Expand Up @@ -61,14 +61,8 @@ shouldBe(Reflect.getPrototypeOf(namespace), null);

// These names should be shown in the code point order.
shouldBe(JSON.stringify(Object.getOwnPropertyNames(namespace)), `["Cappuccino","Cocoa","Matcha","Mocha","default"]`);
shouldBe(Object.getOwnPropertySymbols(namespace).length, 2);
shouldBe(Object.getOwnPropertySymbols(namespace)[0], Symbol.iterator);
shouldBe(Object.getOwnPropertySymbols(namespace)[1], Symbol.toStringTag);

shouldBe(typeof namespace[Symbol.iterator], 'function');
var array = Array.from(namespace);
// These names should be shown in the code point order.
shouldBe(JSON.stringify(array), `["Cappuccino","Cocoa","Matcha","Mocha","default"]`);
shouldBe(Object.getOwnPropertySymbols(namespace).length, 1);
shouldBe(Object.getOwnPropertySymbols(namespace)[0], Symbol.toStringTag);

// The imported binding properties of the namespace object seen as writable, but, it does not mean that it is writable by users.
shouldBe(JSON.stringify(Reflect.getOwnPropertyDescriptor(namespace, "Cocoa")), `{"value":"Cocoa","writable":true,"enumerable":true,"configurable":false}`);
Expand All @@ -79,10 +73,9 @@ shouldThrow(() => {
namespace.Cocoa = 'Cocoa';
}, `TypeError: Attempted to assign to readonly property.`);

// In the case of non imported properties, we just return the original descriptor.
// But still these properties cannot be changed.
shouldBe(JSON.stringify(Reflect.getOwnPropertyDescriptor(namespace, Symbol.iterator)), `{"writable":true,"enumerable":false,"configurable":true}`);
shouldBe(JSON.stringify(Reflect.getOwnPropertyDescriptor(namespace, Symbol.toStringTag)), `{"value":"Module","writable":false,"enumerable":false,"configurable":false}`);
shouldThrow(() => {
namespace[Symbol.iterator] = 42;
namespace[Symbol.toStringTag] = 42;
}, `TypeError: Attempted to assign to readonly property.`);

shouldBe(Reflect.deleteProperty(namespace, Symbol.toStringTag), false);
21 changes: 21 additions & 0 deletions Source/JavaScriptCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
2017-02-16 Yusuke Suzuki <[email protected]>

[JSC] Update module namespace object according to the latest ECMA262
https://bugs.webkit.org/show_bug.cgi?id=168280

Reviewed by Saam Barati.

Reflect updates to the module namespace object.

1. @@iterator property is dropped[1].
2. @@toStringTag property becomes non-configurable[1].
3. delete with Symbol should be delegated to the JSObject's one[2].

[1]: https://tc39.github.io/ecma262/#sec-module-namespace-objects
[2]: https://github.com/tc39/ecma262/pull/767

* runtime/JSModuleNamespaceObject.cpp:
(JSC::JSModuleNamespaceObject::finishCreation):
(JSC::JSModuleNamespaceObject::deleteProperty):
(JSC::moduleNamespaceObjectSymbolIterator): Deleted.

2017-02-16 Carlos Garcia Campos <[email protected]>

Unreviewed. Fix the build after r212424.
Expand Down
26 changes: 6 additions & 20 deletions Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,18 @@
#include "Error.h"
#include "JSCInlines.h"
#include "JSModuleEnvironment.h"
#include "JSPropertyNameIterator.h"

namespace JSC {

static EncodedJSValue JSC_HOST_CALL moduleNamespaceObjectSymbolIterator(ExecState*);

const ClassInfo JSModuleNamespaceObject::s_info = { "ModuleNamespaceObject", &Base::s_info, nullptr, CREATE_METHOD_TABLE(JSModuleNamespaceObject) };


JSModuleNamespaceObject::JSModuleNamespaceObject(VM& vm, Structure* structure)
: Base(vm, structure)
, m_exports()
{
}

void JSModuleNamespaceObject::finishCreation(ExecState* exec, JSGlobalObject* globalObject, AbstractModuleRecord* moduleRecord, const IdentifierSet& exports)
void JSModuleNamespaceObject::finishCreation(ExecState* exec, JSGlobalObject*, AbstractModuleRecord* moduleRecord, const IdentifierSet& exports)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
Expand All @@ -69,9 +65,7 @@ void JSModuleNamespaceObject::finishCreation(ExecState* exec, JSGlobalObject* gl
m_exports.add(identifier);

m_moduleRecord.set(vm, this, moduleRecord);
JSFunction* iteratorFunction = JSFunction::create(vm, globalObject, 0, ASCIILiteral("[Symbol.iterator]"), moduleNamespaceObjectSymbolIterator, NoIntrinsic);
putDirect(vm, vm.propertyNames->iteratorSymbol, iteratorFunction, DontEnum);
putDirect(vm, vm.propertyNames->toStringTagSymbol, jsString(&vm, "Module"), DontEnum | ReadOnly);
putDirect(vm, vm.propertyNames->toStringTagSymbol, jsString(&vm, "Module"), DontEnum | DontDelete | ReadOnly);

// http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-getprototypeof
// http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-setprototypeof-v
Expand Down Expand Up @@ -181,10 +175,13 @@ bool JSModuleNamespaceObject::putByIndex(JSCell*, ExecState* exec, unsigned, JSV
return false;
}

bool JSModuleNamespaceObject::deleteProperty(JSCell* cell, ExecState*, PropertyName propertyName)
bool JSModuleNamespaceObject::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName)
{
// http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-delete-p
JSModuleNamespaceObject* thisObject = jsCast<JSModuleNamespaceObject*>(cell);
if (propertyName.isSymbol())
return JSObject::deleteProperty(thisObject, exec, propertyName);

return !thisObject->m_exports.contains(propertyName.uid());
}

Expand All @@ -208,15 +205,4 @@ bool JSModuleNamespaceObject::defineOwnProperty(JSObject*, ExecState* exec, Prop
return false;
}

EncodedJSValue JSC_HOST_CALL moduleNamespaceObjectSymbolIterator(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

JSModuleNamespaceObject* object = jsDynamicCast<JSModuleNamespaceObject*>(vm, exec->thisValue());
if (!object)
return throwVMTypeError(exec, scope, ASCIILiteral("|this| should be a module namespace object"));
return JSValue::encode(JSPropertyNameIterator::create(exec, exec->lexicalGlobalObject()->propertyNameIteratorStructure(), object));
}

} // namespace JSC

0 comments on commit 920bd4c

Please sign in to comment.