Commit 08ee4d3a authored by dslomov@chromium.org's avatar dslomov@chromium.org

Add remaining @@toStringTag symbols to builtins

R=dslomov@chromium.org

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

Patch from Caitlin Potter <caitpotter88@gmail.com>.

Cr-Commit-Position: refs/heads/master@{#24885}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24885 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c9ea8d65
...@@ -112,6 +112,8 @@ function SetUpArrayIterator() { ...@@ -112,6 +112,8 @@ function SetUpArrayIterator() {
%FunctionSetName(ArrayIteratorIterator, '[Symbol.iterator]'); %FunctionSetName(ArrayIteratorIterator, '[Symbol.iterator]');
%AddNamedProperty(ArrayIterator.prototype, symbolIterator, %AddNamedProperty(ArrayIterator.prototype, symbolIterator,
ArrayIteratorIterator, DONT_ENUM); ArrayIteratorIterator, DONT_ENUM);
%AddNamedProperty(ArrayIterator.prototype, symbolToStringTag,
"Array Iterator", READ_ONLY | DONT_ENUM);
} }
SetUpArrayIterator(); SetUpArrayIterator();
......
...@@ -77,6 +77,8 @@ function SetUpSetIterator() { ...@@ -77,6 +77,8 @@ function SetUpSetIterator() {
%FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]'); %FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]');
%AddNamedProperty(SetIterator.prototype, symbolIterator, %AddNamedProperty(SetIterator.prototype, symbolIterator,
SetIteratorSymbolIterator, DONT_ENUM); SetIteratorSymbolIterator, DONT_ENUM);
%AddNamedProperty(SetIterator.prototype, symbolToStringTag,
"Set Iterator", READ_ONLY | DONT_ENUM);
} }
SetUpSetIterator(); SetUpSetIterator();
...@@ -174,6 +176,8 @@ function SetUpMapIterator() { ...@@ -174,6 +176,8 @@ function SetUpMapIterator() {
%FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]'); %FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
%AddNamedProperty(MapIterator.prototype, symbolIterator, %AddNamedProperty(MapIterator.prototype, symbolIterator,
MapIteratorSymbolIterator, DONT_ENUM); MapIteratorSymbolIterator, DONT_ENUM);
%AddNamedProperty(MapIterator.prototype, symbolToStringTag,
"Map Iterator", READ_ONLY | DONT_ENUM);
} }
SetUpMapIterator(); SetUpMapIterator();
......
...@@ -1711,11 +1711,11 @@ bool V8HeapExplorer::ExtractAccessorPairProperty( ...@@ -1711,11 +1711,11 @@ bool V8HeapExplorer::ExtractAccessorPairProperty(
AccessorPair* accessors = AccessorPair::cast(callback_obj); AccessorPair* accessors = AccessorPair::cast(callback_obj);
Object* getter = accessors->getter(); Object* getter = accessors->getter();
if (!getter->IsOddball()) { 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(); Object* setter = accessors->setter();
if (!setter->IsOddball()) { 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; return true;
} }
......
...@@ -220,6 +220,8 @@ function JSONStringify(value, replacer, space) { ...@@ -220,6 +220,8 @@ function JSONStringify(value, replacer, space) {
function SetUpJSON() { function SetUpJSON() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
%AddNamedProperty($JSON, symbolToStringTag, "JSON", READ_ONLY | DONT_ENUM);
// Set up non-enumerable properties of the JSON object. // Set up non-enumerable properties of the JSON object.
InstallFunctions($JSON, DONT_ENUM, $Array( InstallFunctions($JSON, DONT_ENUM, $Array(
"parse", JSONParse, "parse", JSONParse,
......
...@@ -321,6 +321,8 @@ function SetUpMath() { ...@@ -321,6 +321,8 @@ function SetUpMath() {
%AddNamedProperty(global, "Math", $Math, DONT_ENUM); %AddNamedProperty(global, "Math", $Math, DONT_ENUM);
%FunctionSetInstanceClassName(MathConstructor, 'Math'); %FunctionSetInstanceClassName(MathConstructor, 'Math');
%AddNamedProperty($Math, symbolToStringTag, "Math", READ_ONLY | DONT_ENUM);
// Set up math constants. // Set up math constants.
InstallConstants($Math, $Array( InstallConstants($Math, $Array(
// ECMA-262, section 15.8.1.1. // ECMA-262, section 15.8.1.1.
......
...@@ -67,13 +67,32 @@ RUNTIME_FUNCTION(Runtime_FunctionGetName) { ...@@ -67,13 +67,32 @@ RUNTIME_FUNCTION(Runtime_FunctionGetName) {
} }
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) { RUNTIME_FUNCTION(Runtime_FunctionSetName) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 2); DCHECK(args.length() == 2);
CONVERT_ARG_CHECKED(JSFunction, f, 0); CONVERT_ARG_HANDLE_CHECKED(JSFunction, f, 0);
CONVERT_ARG_CHECKED(String, name, 1); CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
f->shared()->set_name(name);
f->shared()->set_name(*NameToFunctionName(name));
return isolate->heap()->undefined_value(); return isolate->heap()->undefined_value();
} }
......
...@@ -87,6 +87,8 @@ function SetUpStringIterator() { ...@@ -87,6 +87,8 @@ function SetUpStringIterator() {
%FunctionSetName(StringIteratorIterator, '[Symbol.iterator]'); %FunctionSetName(StringIteratorIterator, '[Symbol.iterator]');
%AddNamedProperty(StringIterator.prototype, symbolIterator, %AddNamedProperty(StringIterator.prototype, symbolIterator,
StringIteratorIterator, DONT_ENUM); StringIteratorIterator, DONT_ENUM);
%AddNamedProperty(StringIterator.prototype, symbolToStringTag,
"String Iterator", READ_ONLY | DONT_ENUM);
} }
SetUpStringIterator(); SetUpStringIterator();
......
...@@ -291,6 +291,13 @@ function TypedArraySet(obj, offset) { ...@@ -291,6 +291,13 @@ function TypedArraySet(obj, offset) {
} }
} }
function TypedArrayGetToStringTag() {
if (!%IsTypedArray(this)) return;
var name = %_ClassOf(this);
if (IS_UNDEFINED(name)) return;
return name;
}
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function SetupTypedArrays() { function SetupTypedArrays() {
...@@ -310,7 +317,8 @@ macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) ...@@ -310,7 +317,8 @@ macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset); InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset);
InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength); InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength);
InstallGetter(global.NAME.prototype, "length", NAME_GetLength); InstallGetter(global.NAME.prototype, "length", NAME_GetLength);
InstallGetter(global.NAME.prototype, symbolToStringTag,
TypedArrayGetToStringTag);
InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array( InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
"subarray", NAMESubArray, "subarray", NAMESubArray,
"set", TypedArraySet "set", TypedArraySet
...@@ -437,6 +445,8 @@ function SetupDataView() { ...@@ -437,6 +445,8 @@ function SetupDataView() {
// Set up constructor property on the DataView prototype. // Set up constructor property on the DataView prototype.
%AddNamedProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM); %AddNamedProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM);
%AddNamedProperty(
$DataView.prototype, symbolToStringTag, "DataView", READ_ONLY|DONT_ENUM);
InstallGetter($DataView.prototype, "buffer", DataViewGetBufferJS); InstallGetter($DataView.prototype, "buffer", DataViewGetBufferJS);
InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset); InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset);
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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; var NONE = 0;
...@@ -158,6 +158,15 @@ function TestArrayIteratorPrototype() { ...@@ -158,6 +158,15 @@ function TestArrayIteratorPrototype() {
Object.getOwnPropertyNames(ArrayIteratorPrototype)); Object.getOwnPropertyNames(ArrayIteratorPrototype));
assertHasOwnProperty(ArrayIteratorPrototype, 'next', DONT_ENUM); assertHasOwnProperty(ArrayIteratorPrototype, 'next', DONT_ENUM);
assertHasOwnProperty(ArrayIteratorPrototype, Symbol.iterator, 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(); TestArrayIteratorPrototype();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Flags: --allow-natives-syntax // Flags: --allow-natives-syntax --harmony-tostring
(function TestSetIterator() { (function TestSetIterator() {
...@@ -19,6 +19,15 @@ ...@@ -19,6 +19,15 @@
assertEquals(new Set().values().__proto__, SetIteratorPrototype); assertEquals(new Set().values().__proto__, SetIteratorPrototype);
assertEquals(new Set().entries().__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 @@ ...@@ -120,6 +129,15 @@
assertEquals(new Map().values().__proto__, MapIteratorPrototype); assertEquals(new Map().values().__proto__, MapIteratorPrototype);
assertEquals(new Map().keys().__proto__, MapIteratorPrototype); assertEquals(new Map().keys().__proto__, MapIteratorPrototype);
assertEquals(new Map().entries().__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);
})(); })();
......
// 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();
// 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();
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Flags: --harmony-tostring
function TestStringPrototypeIterator() { function TestStringPrototypeIterator() {
assertTrue(String.prototype.hasOwnProperty(Symbol.iterator)); assertTrue(String.prototype.hasOwnProperty(Symbol.iterator));
...@@ -59,6 +60,12 @@ function TestStringIteratorPrototype() { ...@@ -59,6 +60,12 @@ function TestStringIteratorPrototype() {
assertArrayEquals(['next'], assertArrayEquals(['next'],
Object.getOwnPropertyNames(StringIteratorPrototype)); Object.getOwnPropertyNames(StringIteratorPrototype));
assertEquals('[object String Iterator]', "" + iterator); 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(); TestStringIteratorPrototype();
......
...@@ -265,6 +265,17 @@ function TestTypedArray(constr, elementSize, typicalElement) { ...@@ -265,6 +265,17 @@ function TestTypedArray(constr, elementSize, typicalElement) {
assertSame(0, aNoParam.length); assertSame(0, aNoParam.length);
assertSame(0, aNoParam.byteLength); assertSame(0, aNoParam.byteLength);
assertSame(0, aNoParam.byteOffset); 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); TestTypedArray(Uint8Array, 1, 0xFF);
...@@ -654,6 +665,19 @@ function TestDataViewPropertyTypeChecks() { ...@@ -654,6 +665,19 @@ function TestDataViewPropertyTypeChecks() {
TestDataViewPropertyTypeChecks(); 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 // General tests for properties
// Test property attribute [[Enumerable]] // Test property attribute [[Enumerable]]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment