Commit 2279dfe7 authored by arv's avatar arv Committed by Commit bot

[es6] Map/Set size getter should have "get size" name

This reverts commit d5565c1f.

Getter and setter function names in ES6 are defined as "get foo" and
"set foo".

This also moves the logic for handling symbols from runtime-function.cc
to v8natives.js.

BUG=None
LOG=N
R=adamk@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#28050}
parent 968715c6
......@@ -128,7 +128,7 @@ function ArrayKeys() {
InstallFunctions(ArrayIterator.prototype, DONT_ENUM, [
'next', ArrayIteratorNext
]);
%FunctionSetName(ArrayIteratorIterator, '[Symbol.iterator]');
SetFunctionName(ArrayIteratorIterator, symbolIterator);
%AddNamedProperty(ArrayIterator.prototype, symbolIterator,
ArrayIteratorIterator, DONT_ENUM);
%AddNamedProperty(ArrayIterator.prototype, symbolToStringTag,
......
......@@ -80,7 +80,7 @@ InstallFunctions(SetIterator.prototype, DONT_ENUM, [
'next', SetIteratorNextJS
]);
%FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]');
SetFunctionName(SetIteratorSymbolIterator, symbolIterator);
%AddNamedProperty(SetIterator.prototype, symbolIterator,
SetIteratorSymbolIterator, DONT_ENUM);
%AddNamedProperty(SetIterator.prototype, symbolToStringTag,
......@@ -170,7 +170,7 @@ InstallFunctions(MapIterator.prototype, DONT_ENUM, [
'next', MapIteratorNextJS
]);
%FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
SetFunctionName(MapIteratorSymbolIterator, symbolIterator);
%AddNamedProperty(MapIterator.prototype, symbolIterator,
MapIteratorSymbolIterator, DONT_ENUM);
%AddNamedProperty(MapIterator.prototype, symbolToStringTag,
......
......@@ -95,7 +95,7 @@ InstallFunctions(GeneratorObjectPrototype,
["next", GeneratorObjectNext,
"throw", GeneratorObjectThrow]);
%FunctionSetName(GeneratorObjectIterator, '[Symbol.iterator]');
SetFunctionName(GeneratorObjectIterator, symbolIterator);
%AddNamedProperty(GeneratorObjectPrototype, symbolIterator,
GeneratorObjectIterator, DONT_ENUM | DONT_DELETE | READ_ONLY);
%AddNamedProperty(GeneratorObjectPrototype, "constructor",
......
......@@ -254,7 +254,7 @@ function addBoundMethod(obj, methodName, implementation, length) {
}
}
}
%FunctionSetName(boundMethod, internalName);
SetFunctionName(boundMethod, internalName);
%FunctionRemovePrototype(boundMethod);
%SetNativeFlag(boundMethod);
this[internalName] = boundMethod;
......@@ -262,7 +262,7 @@ function addBoundMethod(obj, methodName, implementation, length) {
return this[internalName];
}
%FunctionSetName(getter, methodName);
SetFunctionName(getter, methodName);
%FunctionRemovePrototype(getter);
%SetNativeFlag(getter);
......@@ -990,7 +990,7 @@ function initializeCollator(collator, locales, options) {
},
DONT_ENUM
);
%FunctionSetName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions');
SetFunctionName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions');
%FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions);
%SetNativeFlag(Intl.Collator.prototype.resolvedOptions);
......@@ -1010,7 +1010,7 @@ function initializeCollator(collator, locales, options) {
},
DONT_ENUM
);
%FunctionSetName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf');
SetFunctionName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf');
%FunctionRemovePrototype(Intl.Collator.supportedLocalesOf);
%SetNativeFlag(Intl.Collator.supportedLocalesOf);
......@@ -1234,7 +1234,7 @@ function initializeNumberFormat(numberFormat, locales, options) {
},
DONT_ENUM
);
%FunctionSetName(Intl.NumberFormat.prototype.resolvedOptions,
SetFunctionName(Intl.NumberFormat.prototype.resolvedOptions,
'resolvedOptions');
%FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions);
%SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions);
......@@ -1255,7 +1255,7 @@ function initializeNumberFormat(numberFormat, locales, options) {
},
DONT_ENUM
);
%FunctionSetName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf');
SetFunctionName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf');
%FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf);
%SetNativeFlag(Intl.NumberFormat.supportedLocalesOf);
......@@ -1626,8 +1626,8 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
},
DONT_ENUM
);
%FunctionSetName(Intl.DateTimeFormat.prototype.resolvedOptions,
'resolvedOptions');
SetFunctionName(Intl.DateTimeFormat.prototype.resolvedOptions,
'resolvedOptions');
%FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions);
%SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions);
......@@ -1647,7 +1647,7 @@ function initializeDateTimeFormat(dateFormat, locales, options) {
},
DONT_ENUM
);
%FunctionSetName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf');
SetFunctionName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf');
%FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf);
%SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf);
......@@ -1805,8 +1805,8 @@ function initializeBreakIterator(iterator, locales, options) {
},
DONT_ENUM
);
%FunctionSetName(Intl.v8BreakIterator.prototype.resolvedOptions,
'resolvedOptions');
SetFunctionName(Intl.v8BreakIterator.prototype.resolvedOptions,
'resolvedOptions');
%FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions);
%SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions);
......@@ -1827,7 +1827,7 @@ function initializeBreakIterator(iterator, locales, options) {
},
DONT_ENUM
);
%FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf');
SetFunctionName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf');
%FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf);
%SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf);
......
......@@ -68,32 +68,15 @@ 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) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSFunction, f, 0);
CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
CONVERT_ARG_HANDLE_CHECKED(String, name, 1);
f->shared()->set_name(*NameToFunctionName(name));
name = String::Flatten(name);
f->shared()->set_name(*name);
return isolate->heap()->undefined_value();
}
......
......@@ -91,13 +91,13 @@ function StringPrototypeIterator() {
InstallFunctions(StringIterator.prototype, DONT_ENUM, [
'next', StringIteratorNext
]);
%FunctionSetName(StringIteratorIterator, '[Symbol.iterator]');
SetFunctionName(StringIteratorIterator, symbolIterator);
%AddNamedProperty(StringIterator.prototype, symbolIterator,
StringIteratorIterator, DONT_ENUM);
%AddNamedProperty(StringIterator.prototype, symbolToStringTag,
"String Iterator", READ_ONLY | DONT_ENUM);
%FunctionSetName(StringPrototypeIterator, '[Symbol.iterator]');
SetFunctionName(StringPrototypeIterator, symbolIterator);
%AddNamedProperty(GlobalString.prototype, symbolIterator,
StringPrototypeIterator, DONT_ENUM);
......
......@@ -15,13 +15,26 @@ var $isFinite = GlobalIsFinite;
// ----------------------------------------------------------------------------
// ES6 - 9.2.11 SetFunctionName
function SetFunctionName(f, name, prefix) {
if (IS_SYMBOL(name)) {
name = "[" + %SymbolDescription(name) + "]";
}
if (IS_UNDEFINED(prefix)) {
%FunctionSetName(f, name);
} else {
%FunctionSetName(f, prefix + " " + name);
}
}
// Helper function used to install functions on objects.
function InstallFunctions(object, attributes, functions) {
%OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1);
for (var i = 0; i < functions.length; i += 2) {
var key = functions[i];
var f = functions[i + 1];
%FunctionSetName(f, key);
SetFunctionName(f, key);
%FunctionRemovePrototype(f);
%AddNamedProperty(object, key, f, attributes);
%SetNativeFlag(f);
......@@ -35,7 +48,7 @@ function OverrideFunction(object, name, f) {
writeable: true,
configurable: true,
enumerable: false });
%FunctionSetName(f, name);
SetFunctionName(f, name);
%FunctionRemovePrototype(f);
%SetNativeFlag(f);
}
......@@ -46,7 +59,7 @@ function InstallGetter(object, name, getter, attributes) {
if (typeof attributes == "undefined") {
attributes = DONT_ENUM;
}
%FunctionSetName(getter, name);
SetFunctionName(getter, name, "get");
%FunctionRemovePrototype(getter);
%DefineAccessorPropertyUnchecked(object, name, getter, null, attributes);
%SetNativeFlag(getter);
......@@ -55,8 +68,8 @@ function InstallGetter(object, name, getter, attributes) {
// Helper function to install a getter/setter accessor property.
function InstallGetterSetter(object, name, getter, setter) {
%FunctionSetName(getter, name);
%FunctionSetName(setter, name);
SetFunctionName(getter, name, "get");
SetFunctionName(setter, name, "set");
%FunctionRemovePrototype(getter);
%FunctionRemovePrototype(setter);
%DefineAccessorPropertyUnchecked(object, name, getter, setter, DONT_ENUM);
......
// Copyright 2015 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.
'use strict';
function assertGetterName(expected, object, name) {
var descr = Object.getOwnPropertyDescriptor(object, name);
assertSame(expected, descr.get.name);
}
function assertSetterName(expected, object, name) {
var descr = Object.getOwnPropertyDescriptor(object, name);
assertSame(expected, descr.set.name);
}
assertGetterName('get byteLength', ArrayBuffer.prototype, 'byteLength');
assertGetterName('get size', Set.prototype, 'size');
assertGetterName('get size', Map.prototype, 'size');
let typedArrays = [
Uint8Array,
Int8Array,
Uint16Array,
Int16Array,
Uint32Array,
Int32Array,
Float32Array,
Float64Array,
Uint8ClampedArray
];
for (let f of typedArrays) {
assertGetterName('get buffer', f.prototype, 'buffer');
assertGetterName('get byteOffset', f.prototype, 'byteOffset');
assertGetterName('get byteLength', f.prototype, 'byteLength');
assertGetterName('get length', f.prototype, 'length');
assertGetterName('get [Symbol.toStringTag]', f.prototype, Symbol.toStringTag);
}
assertGetterName('get buffer', DataView.prototype, 'buffer');
assertGetterName('get byteOffset', DataView.prototype, 'byteOffset');
assertGetterName('get byteLength', DataView.prototype, 'byteLength');
assertGetterName('get __proto__', Object.prototype, '__proto__');
assertSetterName('set __proto__', Object.prototype, '__proto__');
......@@ -443,6 +443,7 @@ assertTrue(setSizeDescriptor.get instanceof Function);
assertEquals(undefined, setSizeDescriptor.get.prototype);
assertFalse(setSizeDescriptor.enumerable);
assertTrue(setSizeDescriptor.configurable);
assertEquals('get size', setSizeDescriptor.get.name);
var s = new Set();
assertFalse(s.hasOwnProperty('size'));
......@@ -463,6 +464,7 @@ assertTrue(mapSizeDescriptor.get instanceof Function);
assertEquals(undefined, mapSizeDescriptor.get.prototype);
assertFalse(mapSizeDescriptor.enumerable);
assertTrue(mapSizeDescriptor.configurable);
assertEquals('get size', mapSizeDescriptor.get.name);
var m = new Map();
assertFalse(m.hasOwnProperty('size'));
......
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