Fix set-up of intrinsic's 'constructor' properties
authorrossberg@chromium.org <rossberg@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 11 Apr 2013 12:27:55 +0000 (12:27 +0000)
committerrossberg@chromium.org <rossberg@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 11 Apr 2013 12:27:55 +0000 (12:27 +0000)
Looks so easy...

R=mstarzinger@chromium.org
BUG=229445

Review URL: https://codereview.chromium.org/13880007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14229 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/factory.cc
src/v8natives.js
test/mjsunit/harmony/symbols.js

index fece9a09c91779c6f360d842a7c2b3b9a7a51791..d1c402d27237abfa7090bf9e9a8ea10e62cb6ecb 100644 (file)
@@ -874,14 +874,7 @@ Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name,
     initial_map->set_constructor(*function);
   }
 
-  // Set function.prototype and give the prototype a constructor
-  // property that refers to the function.
   SetPrototypeProperty(function, prototype);
-  // Currently safe because it is only invoked from Genesis.
-  CHECK_NOT_EMPTY_HANDLE(isolate(),
-                         JSObject::SetLocalPropertyIgnoreAttributes(
-                             prototype, constructor_string(),
-                             function, DONT_ENUM));
   return function;
 }
 
index 754fdd6fc7d34c0b5864006d3cd0945c6b960f4a..d848a27c2c8fcef9114224e13f60b0b3c3a3b9ac 100644 (file)
@@ -1356,12 +1356,13 @@ function ObjectConstructor(x) {
 function SetUpObject() {
   %CheckIsBootstrapping();
 
-  $Object.prototype.constructor = $Object;
   %SetCode($Object, ObjectConstructor);
   %FunctionSetName(ObjectPoisonProto, "__proto__");
   %FunctionRemovePrototype(ObjectPoisonProto);
   %SetExpectedNumberOfProperties($Object, 4);
 
+  %SetProperty($Object.prototype, "constructor", $Object, DONT_ENUM);
+
   // Set up non-enumerable functions on the Object.prototype object.
   InstallFunctions($Object.prototype, DONT_ENUM, $Array(
     "toString", ObjectToString,
@@ -1788,8 +1789,8 @@ function NewFunction(arg1) {  // length == 1
 function SetUpFunction() {
   %CheckIsBootstrapping();
 
-  $Function.prototype.constructor = $Function;
   %SetCode($Function, NewFunction);
+  %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM);
 
   InstallFunctions($Function.prototype, DONT_ENUM, $Array(
     "bind", FunctionBind,
index a3f6e57208874274a435d336b23223dce615534c..5eaa1a37d8c4efdfc678d90e4bda06230cc4b093 100644 (file)
@@ -82,6 +82,23 @@ function TestPrototype() {
 TestPrototype()
 
 
+function TestConstructor() {
+  assertFalse(Object === Symbol.prototype.constructor)
+  assertFalse(Symbol === Object.prototype.constructor)
+  assertSame(Symbol, Symbol.prototype.constructor)
+  assertSame(Symbol, Symbol().__proto__.constructor)
+  assertSame(Symbol, Symbol(Symbol()).__proto__.constructor)
+  assertSame(Symbol, (new Symbol).__proto__.constructor)
+  assertSame(Symbol, (new Symbol()).__proto__.constructor)
+  assertSame(Symbol, (new Symbol(Symbol())).__proto__.constructor)
+  assertSame(Symbol, Object(Symbol()).__proto__.constructor)
+  for (var i in symbols) {
+    assertSame(Symbol, symbols[i].__proto__.constructor)
+  }
+}
+TestConstructor()
+
+
 function TestName() {
   for (var i in symbols) {
     var name = symbols[i].name