From d311208e12bb52c7eee7ec95db6175703a16e796 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Thu, 11 Apr 2013 13:31:51 +0000 Subject: [PATCH] Move creation of collection prototypes into JavaScript. R=rossberg@chromium.org Review URL: https://codereview.chromium.org/14165004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14234 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/bootstrapper.cc | 22 +++++++++------------- src/collection.js | 3 +++ test/mjsunit/harmony/collections.js | 23 ++++++++++++++++++++++- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index a7c2bac..d071f45 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -1275,31 +1275,27 @@ void Genesis::InitializeExperimentalGlobal() { if (FLAG_harmony_collections) { { // -- S e t - Handle prototype = - factory()->NewJSObject(isolate()->object_function(), TENURED); InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize, - prototype, Builtins::kIllegal, true); + isolate()->initial_object_prototype(), + Builtins::kIllegal, true); } { // -- M a p - Handle prototype = - factory()->NewJSObject(isolate()->object_function(), TENURED); InstallFunction(global, "Map", JS_MAP_TYPE, JSMap::kSize, - prototype, Builtins::kIllegal, true); + isolate()->initial_object_prototype(), + Builtins::kIllegal, true); } { // -- W e a k M a p - Handle prototype = - factory()->NewJSObject(isolate()->object_function(), TENURED); InstallFunction(global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize, - prototype, Builtins::kIllegal, true); + isolate()->initial_object_prototype(), + Builtins::kIllegal, true); } } if (FLAG_harmony_typed_arrays) { - { // -- A r r a y B u f f e r - Handle prototype = - factory()->NewJSObject(isolate()->object_function(), TENURED); + { // -- A r r a y B u f f e r InstallFunction(global, "__ArrayBuffer", JS_ARRAY_BUFFER_TYPE, - JSArrayBuffer::kSize, prototype, + JSArrayBuffer::kSize, + isolate()->initial_object_prototype(), Builtins::kIllegal, true); } } diff --git a/src/collection.js b/src/collection.js index b1257a3..950c7e7 100644 --- a/src/collection.js +++ b/src/collection.js @@ -117,6 +117,7 @@ function SetUpSet() { %CheckIsBootstrapping(); %SetCode($Set, SetConstructor); + %FunctionSetPrototype($Set, new $Object()); %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); // Set up the non-enumerable functions on the Set prototype object. @@ -217,6 +218,7 @@ function SetUpMap() { %CheckIsBootstrapping(); %SetCode($Map, MapConstructor); + %FunctionSetPrototype($Map, new $Object()); %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); // Set up the non-enumerable functions on the Map prototype object. @@ -299,6 +301,7 @@ function SetUpWeakMap() { %CheckIsBootstrapping(); %SetCode($WeakMap, WeakMapConstructor); + %FunctionSetPrototype($WeakMap, new $Object()); %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); // Set up the non-enumerable functions on the WeakMap prototype object. diff --git a/test/mjsunit/harmony/collections.js b/test/mjsunit/harmony/collections.js index 0219f39..d60c59c 100644 --- a/test/mjsunit/harmony/collections.js +++ b/test/mjsunit/harmony/collections.js @@ -25,7 +25,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// Flags: --harmony-collections --expose-gc +// Flags: --harmony-collections --expose-gc --allow-natives-syntax // Test valid getter and setter calls on Sets. @@ -254,6 +254,27 @@ assertTrue(WeakMap.prototype.has instanceof Function) assertTrue(WeakMap.prototype.delete instanceof Function) +// Test class of the Set, Map and WeakMap instance and prototype. +assertEquals("Set", %_ClassOf(new Set)) +assertEquals("Object", %_ClassOf(Set.prototype)) +assertEquals("Map", %_ClassOf(new Map)) +assertEquals("Object", %_ClassOf(Map.prototype)) +assertEquals("WeakMap", %_ClassOf(new WeakMap)) +assertEquals("Object", %_ClassOf(WeakMap.prototype)) + + +// Test constructor property of the Set, Map and WeakMap prototype. +function TestConstructor(C) { + assertFalse(C === Object.prototype.constructor); + assertSame(C, C.prototype.constructor); + assertSame(C, C().__proto__.constructor); + assertSame(C, (new C).__proto__.constructor); +} +TestConstructor(Set); +TestConstructor(Map); +TestConstructor(WeakMap); + + // Regression test for WeakMap prototype. assertTrue(WeakMap.prototype.constructor === WeakMap) assertTrue(Object.getPrototypeOf(WeakMap.prototype) === Object.prototype) -- 2.7.4