%FunctionSetName(ArrayIteratorIterator, '[Symbol.iterator]');
%AddNamedProperty(ArrayIterator.prototype, symbolIterator,
ArrayIteratorIterator, DONT_ENUM);
+ %AddNamedProperty(ArrayIterator.prototype, symbolToStringTag,
+ "Array Iterator", READ_ONLY | DONT_ENUM);
}
SetUpArrayIterator();
%FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]');
%AddNamedProperty(SetIterator.prototype, symbolIterator,
SetIteratorSymbolIterator, DONT_ENUM);
+ %AddNamedProperty(SetIterator.prototype, symbolToStringTag,
+ "Set Iterator", READ_ONLY | DONT_ENUM);
}
SetUpSetIterator();
%FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
%AddNamedProperty(MapIterator.prototype, symbolIterator,
MapIteratorSymbolIterator, DONT_ENUM);
+ %AddNamedProperty(MapIterator.prototype, symbolToStringTag,
+ "Map Iterator", READ_ONLY | DONT_ENUM);
}
SetUpMapIterator();
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;
}
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,
%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.
}
+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();
}
%FunctionSetName(StringIteratorIterator, '[Symbol.iterator]');
%AddNamedProperty(StringIterator.prototype, symbolIterator,
StringIteratorIterator, DONT_ENUM);
+ %AddNamedProperty(StringIterator.prototype, symbolToStringTag,
+ "String Iterator", READ_ONLY | DONT_ENUM);
}
SetUpStringIterator();
}
}
+function TypedArrayGetToStringTag() {
+ if (!%IsTypedArray(this)) return;
+ var name = %_ClassOf(this);
+ if (IS_UNDEFINED(name)) return;
+ return name;
+}
+
// -------------------------------------------------------------------
function SetupTypedArrays() {
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
// 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);
// (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;
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();
// 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() {
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);
})();
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);
})();
--- /dev/null
+// 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
+// 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();
// 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));
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();
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);
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]]