Revision: 24885
Author: [email protected]
Date: Fri Oct 24 19:28:23 2014 UTC
Log: Add remaining @@toStringTag symbols to builtins
[email protected]
Review URL: https://codereview.chromium.org/664333003
Patch from Caitlin Potter <[email protected]>.
https://code.google.com/p/v8/source/detail?r=24885
Added:
/branches/bleeding_edge/test/mjsunit/es6/json.js
/branches/bleeding_edge/test/mjsunit/es6/math.js
Modified:
/branches/bleeding_edge/src/array-iterator.js
/branches/bleeding_edge/src/collection-iterator.js
/branches/bleeding_edge/src/heap-snapshot-generator.cc
/branches/bleeding_edge/src/json.js
/branches/bleeding_edge/src/math.js
/branches/bleeding_edge/src/runtime/runtime-function.cc
/branches/bleeding_edge/src/string-iterator.js
/branches/bleeding_edge/src/typedarray.js
/branches/bleeding_edge/test/mjsunit/es6/array-iterator.js
/branches/bleeding_edge/test/mjsunit/es6/collection-iterator.js
/branches/bleeding_edge/test/mjsunit/es6/string-iterator.js
/branches/bleeding_edge/test/mjsunit/harmony/typedarrays.js
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/es6/json.js Fri Oct 24 19:28:23
2014 UTC
@@ -0,0 +1,15 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-tostring
+
+function testJSONToString() {
+ assertEquals('[object JSON]', "" + JSON);
+ assertEquals("JSON", JSON[Symbol.toStringTag]);
+ var desc = Object.getOwnPropertyDescriptor(JSON, Symbol.toStringTag);
+ assertTrue(desc.configurable);
+ assertFalse(desc.writable);
+ assertEquals("JSON", desc.value);
+}
+testJSONToString();
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/es6/math.js Fri Oct 24 19:28:23
2014 UTC
@@ -0,0 +1,15 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-tostring
+
+function testMathToString() {
+ assertEquals('[object Math]', "" + Math);
+ assertEquals("Math", Math[Symbol.toStringTag]);
+ var desc = Object.getOwnPropertyDescriptor(Math, Symbol.toStringTag);
+ assertTrue(desc.configurable);
+ assertFalse(desc.writable);
+ assertEquals("Math", desc.value);
+}
+testMathToString();
=======================================
--- /branches/bleeding_edge/src/array-iterator.js Fri Oct 17 20:11:47 2014
UTC
+++ /branches/bleeding_edge/src/array-iterator.js Fri Oct 24 19:28:23 2014
UTC
@@ -112,6 +112,8 @@
%FunctionSetName(ArrayIteratorIterator, '[Symbol.iterator]');
%AddNamedProperty(ArrayIterator.prototype, symbolIterator,
ArrayIteratorIterator, DONT_ENUM);
+ %AddNamedProperty(ArrayIterator.prototype, symbolToStringTag,
+ "Array Iterator", READ_ONLY | DONT_ENUM);
}
SetUpArrayIterator();
=======================================
--- /branches/bleeding_edge/src/collection-iterator.js Mon Jul 14 14:05:30
2014 UTC
+++ /branches/bleeding_edge/src/collection-iterator.js Fri Oct 24 19:28:23
2014 UTC
@@ -77,6 +77,8 @@
%FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]');
%AddNamedProperty(SetIterator.prototype, symbolIterator,
SetIteratorSymbolIterator, DONT_ENUM);
+ %AddNamedProperty(SetIterator.prototype, symbolToStringTag,
+ "Set Iterator", READ_ONLY | DONT_ENUM);
}
SetUpSetIterator();
@@ -174,6 +176,8 @@
%FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
%AddNamedProperty(MapIterator.prototype, symbolIterator,
MapIteratorSymbolIterator, DONT_ENUM);
+ %AddNamedProperty(MapIterator.prototype, symbolToStringTag,
+ "Map Iterator", READ_ONLY | DONT_ENUM);
}
SetUpMapIterator();
=======================================
--- /branches/bleeding_edge/src/heap-snapshot-generator.cc Wed Oct 1
11:53:29 2014 UTC
+++ /branches/bleeding_edge/src/heap-snapshot-generator.cc Fri Oct 24
19:28:23 2014 UTC
@@ -1711,11 +1711,11 @@
AccessorPair* accessors = AccessorPair::cast(callback_obj);
Object* getter = accessors->getter();
if (!getter->IsOddball()) {
- SetPropertyReference(js_obj, entry, String::cast(key),
getter, "get %s");
+ SetPropertyReference(js_obj, entry, Name::cast(key), getter, "get %s");
}
Object* setter = accessors->setter();
if (!setter->IsOddball()) {
- SetPropertyReference(js_obj, entry, String::cast(key),
setter, "set %s");
+ SetPropertyReference(js_obj, entry, Name::cast(key), setter, "set %s");
}
return true;
}
=======================================
--- /branches/bleeding_edge/src/json.js Mon May 12 08:43:01 2014 UTC
+++ /branches/bleeding_edge/src/json.js Fri Oct 24 19:28:23 2014 UTC
@@ -220,6 +220,8 @@
function SetUpJSON() {
%CheckIsBootstrapping();
+ %AddNamedProperty($JSON, symbolToStringTag, "JSON", READ_ONLY |
DONT_ENUM);
+
// Set up non-enumerable properties of the JSON object.
InstallFunctions($JSON, DONT_ENUM, $Array(
"parse", JSONParse,
=======================================
--- /branches/bleeding_edge/src/math.js Mon Oct 20 08:40:46 2014 UTC
+++ /branches/bleeding_edge/src/math.js Fri Oct 24 19:28:23 2014 UTC
@@ -321,6 +321,8 @@
%AddNamedProperty(global, "Math", $Math, DONT_ENUM);
%FunctionSetInstanceClassName(MathConstructor, 'Math');
+ %AddNamedProperty($Math, symbolToStringTag, "Math", READ_ONLY |
DONT_ENUM);
+
// Set up math constants.
InstallConstants($Math, $Array(
// ECMA-262, section 15.8.1.1.
=======================================
--- /branches/bleeding_edge/src/runtime/runtime-function.cc Mon Oct 20
12:07:45 2014 UTC
+++ /branches/bleeding_edge/src/runtime/runtime-function.cc Fri Oct 24
19:28:23 2014 UTC
@@ -65,15 +65,34 @@
CONVERT_ARG_CHECKED(JSFunction, f, 0);
return f->shared()->name();
}
+
+
+static Handle<String> NameToFunctionName(Handle<Name> name) {
+ Handle<String> stringName(name->GetHeap()->empty_string());
+
+ // TODO(caitp): Follow proper rules in section 9.2.11 (SetFunctionName)
+ if (name->IsSymbol()) {
+ Handle<Object> description(Handle<Symbol>::cast(name)->name(),
+ name->GetIsolate());
+ if (description->IsString()) {
+ stringName = Handle<String>::cast(description);
+ }
+ } else {
+ stringName = Handle<String>::cast(name);
+ }
+
+ return stringName;
+}
RUNTIME_FUNCTION(Runtime_FunctionSetName) {
- SealHandleScope shs(isolate);
+ HandleScope scope(isolate);
DCHECK(args.length() == 2);
- CONVERT_ARG_CHECKED(JSFunction, f, 0);
- CONVERT_ARG_CHECKED(String, name, 1);
- f->shared()->set_name(name);
+ CONVERT_ARG_HANDLE_CHECKED(JSFunction, f, 0);
+ CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
+
+ f->shared()->set_name(*NameToFunctionName(name));
return isolate->heap()->undefined_value();
}
=======================================
--- /branches/bleeding_edge/src/string-iterator.js Wed Aug 20 19:21:56 2014
UTC
+++ /branches/bleeding_edge/src/string-iterator.js Fri Oct 24 19:28:23 2014
UTC
@@ -87,6 +87,8 @@
%FunctionSetName(StringIteratorIterator, '[Symbol.iterator]');
%AddNamedProperty(StringIterator.prototype, symbolIterator,
StringIteratorIterator, DONT_ENUM);
+ %AddNamedProperty(StringIterator.prototype, symbolToStringTag,
+ "String Iterator", READ_ONLY | DONT_ENUM);
}
SetUpStringIterator();
=======================================
--- /branches/bleeding_edge/src/typedarray.js Mon Jul 14 14:05:30 2014 UTC
+++ /branches/bleeding_edge/src/typedarray.js Fri Oct 24 19:28:23 2014 UTC
@@ -290,6 +290,13 @@
return;
}
}
+
+function TypedArrayGetToStringTag() {
+ if (!%IsTypedArray(this)) return;
+ var name = %_ClassOf(this);
+ if (IS_UNDEFINED(name)) return;
+ return name;
+}
// -------------------------------------------------------------------
@@ -310,7 +317,8 @@
InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset);
InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength);
InstallGetter(global.NAME.prototype, "length", NAME_GetLength);
-
+ InstallGetter(global.NAME.prototype, symbolToStringTag,
+ TypedArrayGetToStringTag);
InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
"subarray", NAMESubArray,
"set", TypedArraySet
@@ -437,6 +445,8 @@
// Set up constructor property on the DataView prototype.
%AddNamedProperty($DataView.prototype, "constructor", $DataView,
DONT_ENUM);
+ %AddNamedProperty(
+ $DataView.prototype, symbolToStringTag, "DataView", READ_ONLY|
DONT_ENUM);
InstallGetter($DataView.prototype, "buffer", DataViewGetBufferJS);
InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset);
=======================================
--- /branches/bleeding_edge/test/mjsunit/es6/array-iterator.js Fri Oct 17
20:11:47 2014 UTC
+++ /branches/bleeding_edge/test/mjsunit/es6/array-iterator.js Fri Oct 24
19:28:23 2014 UTC
@@ -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: --allow-natives-syntax
+// Flags: --allow-natives-syntax --harmony-tostring
var NONE = 0;
@@ -158,6 +158,15 @@
Object.getOwnPropertyNames(ArrayIteratorPrototype));
assertHasOwnProperty(ArrayIteratorPrototype, 'next', DONT_ENUM);
assertHasOwnProperty(ArrayIteratorPrototype, Symbol.iterator, DONT_ENUM);
+
+ assertEquals("[object Array Iterator]",
+ Object.prototype.toString.call(iterator));
+ assertEquals("Array Iterator",
ArrayIteratorPrototype[Symbol.toStringTag]);
+ var desc = Object.getOwnPropertyDescriptor(
+ ArrayIteratorPrototype, Symbol.toStringTag);
+ assertTrue(desc.configurable);
+ assertFalse(desc.writable);
+ assertEquals("Array Iterator", desc.value);
}
TestArrayIteratorPrototype();
=======================================
--- /branches/bleeding_edge/test/mjsunit/es6/collection-iterator.js Tue
Aug 5 19:37:32 2014 UTC
+++ /branches/bleeding_edge/test/mjsunit/es6/collection-iterator.js Fri Oct
24 19:28:23 2014 UTC
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --allow-natives-syntax
+// Flags: --allow-natives-syntax --harmony-tostring
(function TestSetIterator() {
@@ -19,6 +19,15 @@
assertEquals(new Set().values().__proto__, SetIteratorPrototype);
assertEquals(new Set().entries().__proto__, SetIteratorPrototype);
+
+ assertEquals("[object Set Iterator]",
+ Object.prototype.toString.call(iter));
+ assertEquals("Set Iterator", SetIteratorPrototype[Symbol.toStringTag]);
+ var desc = Object.getOwnPropertyDescriptor(
+ SetIteratorPrototype, Symbol.toStringTag);
+ assertTrue(desc.configurable);
+ assertFalse(desc.writable);
+ assertEquals("Set Iterator", desc.value);
})();
@@ -120,6 +129,15 @@
assertEquals(new Map().values().__proto__, MapIteratorPrototype);
assertEquals(new Map().keys().__proto__, MapIteratorPrototype);
assertEquals(new Map().entries().__proto__, MapIteratorPrototype);
+
+ assertEquals("[object Map Iterator]",
+ Object.prototype.toString.call(iter));
+ assertEquals("Map Iterator", MapIteratorPrototype[Symbol.toStringTag]);
+ var desc = Object.getOwnPropertyDescriptor(
+ MapIteratorPrototype, Symbol.toStringTag);
+ assertTrue(desc.configurable);
+ assertFalse(desc.writable);
+ assertEquals("Map Iterator", desc.value);
})();
=======================================
--- /branches/bleeding_edge/test/mjsunit/es6/string-iterator.js Thu Aug 7
16:42:14 2014 UTC
+++ /branches/bleeding_edge/test/mjsunit/es6/string-iterator.js Fri Oct 24
19:28:23 2014 UTC
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// Flags: --harmony-tostring
function TestStringPrototypeIterator() {
assertTrue(String.prototype.hasOwnProperty(Symbol.iterator));
@@ -59,6 +60,12 @@
assertArrayEquals(['next'],
Object.getOwnPropertyNames(StringIteratorPrototype));
assertEquals('[object String Iterator]', "" + iterator);
+ assertEquals("String Iterator",
StringIteratorPrototype[Symbol.toStringTag]);
+ var desc = Object.getOwnPropertyDescriptor(
+ StringIteratorPrototype, Symbol.toStringTag);
+ assertTrue(desc.configurable);
+ assertFalse(desc.writable);
+ assertEquals("String Iterator", desc.value);
}
TestStringIteratorPrototype();
=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/typedarrays.js Tue Oct 21
17:21:32 2014 UTC
+++ /branches/bleeding_edge/test/mjsunit/harmony/typedarrays.js Fri Oct 24
19:28:23 2014 UTC
@@ -265,6 +265,17 @@
assertSame(0, aNoParam.length);
assertSame(0, aNoParam.byteLength);
assertSame(0, aNoParam.byteOffset);
+
+ var a = new constr(ab, 64*elementSize, 128);
+ assertEquals("[object " + constr.name + "]",
+ Object.prototype.toString.call(a));
+ var desc = Object.getOwnPropertyDescriptor(
+ constr.prototype, Symbol.toStringTag);
+ assertTrue(desc.configurable);
+ assertFalse(desc.enumerable);
+ assertFalse(!!desc.writable);
+ assertFalse(!!desc.set);
+ assertEquals("function", typeof desc.get);
}
TestTypedArray(Uint8Array, 1, 0xFF);
@@ -654,6 +665,19 @@
TestDataViewPropertyTypeChecks();
+
+function TestDataViewToStringTag() {
+ var a = new DataView(new ArrayBuffer(10));
+ assertEquals("[object DataView]", Object.prototype.toString.call(a));
+ var desc = Object.getOwnPropertyDescriptor(
+ DataView.prototype, Symbol.toStringTag);
+ assertTrue(desc.configurable);
+ assertFalse(desc.enumerable);
+ assertFalse(desc.writable);
+ assertEquals("DataView", desc.value);
+}
+
+
// General tests for properties
// Test property attribute [[Enumerable]]
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.