[ES6] Add @@toStringTag to GeneratorFunction
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Apr 2016 11:16:24 +0000 (11:16 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Apr 2016 11:16:24 +0000 (11:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156499

Reviewed by Mark Lam.

GeneratorFunction.prototype has @@toStringTag property, "GeneratorFunction".
https://tc39.github.io/ecma262/#sec-generatorfunction.prototype-@@tostringtag

* runtime/GeneratorFunctionPrototype.cpp:
(JSC::GeneratorFunctionPrototype::finishCreation):
* tests/es6.yaml:
* tests/es6/well-known_symbols_Symbol.toStringTag_new_built-ins.js: Added.
(test):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199459 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/GeneratorFunctionPrototype.cpp
Source/JavaScriptCore/tests/es6.yaml
Source/JavaScriptCore/tests/es6/well-known_symbols_Symbol.toStringTag_new_built-ins.js [new file with mode: 0644]

index a44ebad..8310664 100644 (file)
@@ -1,3 +1,19 @@
+2016-04-13  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [ES6] Add @@toStringTag to GeneratorFunction
+        https://bugs.webkit.org/show_bug.cgi?id=156499
+
+        Reviewed by Mark Lam.
+
+        GeneratorFunction.prototype has @@toStringTag property, "GeneratorFunction".
+        https://tc39.github.io/ecma262/#sec-generatorfunction.prototype-@@tostringtag
+
+        * runtime/GeneratorFunctionPrototype.cpp:
+        (JSC::GeneratorFunctionPrototype::finishCreation):
+        * tests/es6.yaml:
+        * tests/es6/well-known_symbols_Symbol.toStringTag_new_built-ins.js: Added.
+        (test):
+
 2016-04-13  Alberto Garcia  <berto@igalia.com>
 
         Fix build in glibc-based BSD systems
 2016-04-13  Alberto Garcia  <berto@igalia.com>
 
         Fix build in glibc-based BSD systems
index 33fe8f2..6a36dab 100644 (file)
@@ -50,7 +50,10 @@ GeneratorFunctionPrototype::GeneratorFunctionPrototype(VM& vm, Structure* struct
 void GeneratorFunctionPrototype::finishCreation(VM& vm)
 {
     Base::finishCreation(vm);
 void GeneratorFunctionPrototype::finishCreation(VM& vm)
 {
     Base::finishCreation(vm);
+    ASSERT(inherits(info()));
     putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(0), DontDelete | ReadOnly | DontEnum);
     putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(0), DontDelete | ReadOnly | DontEnum);
+    putDirectWithoutTransition(vm, vm.propertyNames->toStringTagSymbol, jsString(&vm, "GeneratorFunction"), DontEnum | ReadOnly);
+    vm.prototypeMap.addPrototype(this);
 }
 
 } // namespace JSC
 }
 
 } // namespace JSC
index 75587d0..4e84e43 100644 (file)
   cmd: runES6 :normal
 - path: es6/well-known_symbols_Symbol.toStringTag_misc._built-ins.js
   cmd: runES6 :normal
   cmd: runES6 :normal
 - path: es6/well-known_symbols_Symbol.toStringTag_misc._built-ins.js
   cmd: runES6 :normal
+- path: es6/well-known_symbols_Symbol.toStringTag_new_built-ins.js
+  cmd: runES6 :normal
 - path: es6/well-known_symbols_Symbol.match_String.prototype.startsWith.js
   cmd: runES6 :normal
 - path: es6/well-known_symbols_Symbol.match_String.prototype.endsWith.js
 - path: es6/well-known_symbols_Symbol.match_String.prototype.startsWith.js
   cmd: runES6 :normal
 - path: es6/well-known_symbols_Symbol.match_String.prototype.endsWith.js
diff --git a/Source/JavaScriptCore/tests/es6/well-known_symbols_Symbol.toStringTag_new_built-ins.js b/Source/JavaScriptCore/tests/es6/well-known_symbols_Symbol.toStringTag_new_built-ins.js
new file mode 100644 (file)
index 0000000..691d562
--- /dev/null
@@ -0,0 +1,32 @@
+function test() {
+
+var passed = true;
+var s = Symbol.toStringTag;
+[
+  [String, "String Iterator"],
+  [Array, "Array Iterator"],
+  [Map, "Map Iterator"],
+  [Set, "Set Iterator"]
+].forEach(function(pair){
+  var iterProto = Object.getPrototypeOf(new pair[0]()[Symbol.iterator]());
+  passed = passed
+    && iterProto.hasOwnProperty(s)
+    && iterProto[s] === pair[1];
+});
+
+passed = passed
+  && Object.getPrototypeOf(function*(){})[s] === "GeneratorFunction"
+  && Object.getPrototypeOf(function*(){}())[s] === "Generator"
+  && Map.prototype[s] === "Map"
+  && Set.prototype[s] === "Set"
+  && ArrayBuffer.prototype[s] === "ArrayBuffer"
+  && DataView.prototype[s] === "DataView"
+  && Promise.prototype[s] === "Promise"
+  && Symbol.prototype[s] === "Symbol"
+  && typeof Object.getOwnPropertyDescriptor(
+    Object.getPrototypeOf(Int8Array).prototype, Symbol.toStringTag).get === "function";
+  return passed;
+}
+
+if (!test())
+    throw new Error("Test failed");