Wrap map and set implementation in functions.

R=jkummerow@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27879}
This commit is contained in:
yangguo 2015-04-16 05:17:46 -07:00 committed by Commit bot
parent d3b788df0a
commit 05bfdd866a
8 changed files with 127 additions and 144 deletions

View File

@ -244,7 +244,7 @@ class AstValue : public ZoneObject {
F(dot_result, ".result") \ F(dot_result, ".result") \
F(empty, "") \ F(empty, "") \
F(eval, "eval") \ F(eval, "eval") \
F(get_template_callsite, "GetTemplateCallSite") \ F(get_template_callsite, "$getTemplateCallSite") \
F(initialize_const_global, "initializeConstGlobal") \ F(initialize_const_global, "initializeConstGlobal") \
F(initialize_var_global, "initializeVarGlobal") \ F(initialize_var_global, "initializeVarGlobal") \
F(is_construct_call, "_IsConstructCall") \ F(is_construct_call, "_IsConstructCall") \

View File

@ -2,14 +2,22 @@
// 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.
var $mapEntries;
var $mapIteratorNext;
var $setIteratorNext;
var $setValues;
(function() {
"use strict"; "use strict";
%CheckIsBootstrapping();
// This file relies on the fact that the following declaration has been made var GlobalMap = global.Map;
// in runtime.js: var GlobalObject = global.Object;
// var $Set = global.Set; var GlobalSet = global.Set;
// var $Map = global.Map;
// -------------------------------------------------------------------
function SetIteratorConstructor(set, kind) { function SetIteratorConstructor(set, kind) {
%SetIteratorInitialize(this, set, kind); %SetIteratorInitialize(this, set, kind);
@ -63,42 +71,33 @@ function SetValues() {
return new SetIterator(this, ITERATOR_KIND_VALUES); return new SetIterator(this, ITERATOR_KIND_VALUES);
} }
// -------------------------------------------------------------------
function SetUpSetIterator() { %SetCode(SetIterator, SetIteratorConstructor);
%CheckIsBootstrapping(); %FunctionSetPrototype(SetIterator, new GlobalObject());
%FunctionSetInstanceClassName(SetIterator, 'Set Iterator');
%SetCode(SetIterator, SetIteratorConstructor); InstallFunctions(SetIterator.prototype, DONT_ENUM, [
%FunctionSetPrototype(SetIterator, new $Object());
%FunctionSetInstanceClassName(SetIterator, 'Set Iterator');
InstallFunctions(SetIterator.prototype, DONT_ENUM, [
'next', SetIteratorNextJS 'next', SetIteratorNextJS
]); ]);
%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, %AddNamedProperty(SetIterator.prototype, symbolToStringTag,
"Set Iterator", READ_ONLY | DONT_ENUM); "Set Iterator", READ_ONLY | DONT_ENUM);
}
SetUpSetIterator(); InstallFunctions(GlobalSet.prototype, DONT_ENUM, [
function ExtendSetPrototype() {
%CheckIsBootstrapping();
InstallFunctions($Set.prototype, DONT_ENUM, [
'entries', SetEntries, 'entries', SetEntries,
'keys', SetValues, 'keys', SetValues,
'values', SetValues 'values', SetValues
]); ]);
%AddNamedProperty($Set.prototype, symbolIterator, SetValues, DONT_ENUM); %AddNamedProperty(GlobalSet.prototype, symbolIterator, SetValues, DONT_ENUM);
}
ExtendSetPrototype();
$setIteratorNext = SetIteratorNextJS;
$setValues = SetValues;
// -------------------------------------------------------------------
function MapIteratorConstructor(map, kind) { function MapIteratorConstructor(map, kind) {
%MapIteratorInitialize(this, map, kind); %MapIteratorInitialize(this, map, kind);
@ -162,37 +161,31 @@ function MapValues() {
return new MapIterator(this, ITERATOR_KIND_VALUES); return new MapIterator(this, ITERATOR_KIND_VALUES);
} }
// -------------------------------------------------------------------
function SetUpMapIterator() { %SetCode(MapIterator, MapIteratorConstructor);
%CheckIsBootstrapping(); %FunctionSetPrototype(MapIterator, new GlobalObject());
%FunctionSetInstanceClassName(MapIterator, 'Map Iterator');
%SetCode(MapIterator, MapIteratorConstructor); InstallFunctions(MapIterator.prototype, DONT_ENUM, [
%FunctionSetPrototype(MapIterator, new $Object());
%FunctionSetInstanceClassName(MapIterator, 'Map Iterator');
InstallFunctions(MapIterator.prototype, DONT_ENUM, [
'next', MapIteratorNextJS 'next', MapIteratorNextJS
]); ]);
%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, %AddNamedProperty(MapIterator.prototype, symbolToStringTag,
"Map Iterator", READ_ONLY | DONT_ENUM); "Map Iterator", READ_ONLY | DONT_ENUM);
}
SetUpMapIterator();
function ExtendMapPrototype() { InstallFunctions(GlobalMap.prototype, DONT_ENUM, [
%CheckIsBootstrapping();
InstallFunctions($Map.prototype, DONT_ENUM, [
'entries', MapEntries, 'entries', MapEntries,
'keys', MapKeys, 'keys', MapKeys,
'values', MapValues 'values', MapValues
]); ]);
%AddNamedProperty($Map.prototype, symbolIterator, MapEntries, DONT_ENUM); %AddNamedProperty(GlobalMap.prototype, symbolIterator, MapEntries, DONT_ENUM);
}
ExtendMapPrototype(); $mapEntries = MapEntries;
$mapIteratorNext = MapIteratorNextJS;
})();

View File

@ -2,20 +2,17 @@
// 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.
"use strict";
// This file relies on the fact that the following declaration has been made
// in runtime.js:
// var $Array = global.Array;
var $Set = global.Set;
var $Map = global.Map;
(function() { (function() {
"use strict";
%CheckIsBootstrapping(); %CheckIsBootstrapping();
var GlobalMap = global.Map;
var GlobalObject = global.Object;
var GlobalSet = global.Set;
// -------------------------------------------------------------------
function HashToEntry(table, hash, numBuckets) { function HashToEntry(table, hash, numBuckets) {
var bucket = ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets); var bucket = ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets);
@ -230,19 +227,20 @@ function SetForEach(f, receiver) {
} }
} }
// -------------------------------------------------------------------
%SetCode($Set, SetConstructor); %SetCode(GlobalSet, SetConstructor);
%FunctionSetLength($Set, 0); %FunctionSetLength(GlobalSet, 0);
%FunctionSetPrototype($Set, new $Object()); %FunctionSetPrototype(GlobalSet, new GlobalObject());
%AddNamedProperty($Set.prototype, "constructor", $Set, DONT_ENUM); %AddNamedProperty(GlobalSet.prototype, "constructor", GlobalSet, DONT_ENUM);
%AddNamedProperty( %AddNamedProperty(GlobalSet.prototype, symbolToStringTag, "Set",
$Set.prototype, symbolToStringTag, "Set", DONT_ENUM | READ_ONLY); DONT_ENUM | READ_ONLY);
%FunctionSetLength(SetForEach, 1); %FunctionSetLength(SetForEach, 1);
// Set up the non-enumerable functions on the Set prototype object. // Set up the non-enumerable functions on the Set prototype object.
InstallGetter($Set.prototype, "size", SetGetSize); InstallGetter(GlobalSet.prototype, "size", SetGetSize);
InstallFunctions($Set.prototype, DONT_ENUM, [ InstallFunctions(GlobalSet.prototype, DONT_ENUM, [
"add", SetAdd, "add", SetAdd,
"has", SetHas, "has", SetHas,
"delete", SetDelete, "delete", SetDelete,
@ -417,19 +415,20 @@ function MapForEach(f, receiver) {
} }
} }
// -------------------------------------------------------------------
%SetCode($Map, MapConstructor); %SetCode(GlobalMap, MapConstructor);
%FunctionSetLength($Map, 0); %FunctionSetLength(GlobalMap, 0);
%FunctionSetPrototype($Map, new $Object()); %FunctionSetPrototype(GlobalMap, new GlobalObject());
%AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM); %AddNamedProperty(GlobalMap.prototype, "constructor", GlobalMap, DONT_ENUM);
%AddNamedProperty( %AddNamedProperty(
$Map.prototype, symbolToStringTag, "Map", DONT_ENUM | READ_ONLY); GlobalMap.prototype, symbolToStringTag, "Map", DONT_ENUM | READ_ONLY);
%FunctionSetLength(MapForEach, 1); %FunctionSetLength(MapForEach, 1);
// Set up the non-enumerable functions on the Map prototype object. // Set up the non-enumerable functions on the Map prototype object.
InstallGetter($Map.prototype, "size", MapGetSize); InstallGetter(GlobalMap.prototype, "size", MapGetSize);
InstallFunctions($Map.prototype, DONT_ENUM, [ InstallFunctions(GlobalMap.prototype, DONT_ENUM, [
"get", MapGet, "get", MapGet,
"set", MapSet, "set", MapSet,
"has", MapHas, "has", MapHas,

View File

@ -1384,7 +1384,7 @@ MapMirror.prototype.entries = function(opt_limit) {
return result; return result;
} }
var iter = %_CallFunction(this.value_, builtins.MapEntries); var iter = %_CallFunction(this.value_, builtins.$mapEntries);
var next; var next;
while ((!opt_limit || result.length < opt_limit) && while ((!opt_limit || result.length < opt_limit) &&
!(next = iter.next()).done) { !(next = iter.next()).done) {
@ -1426,8 +1426,8 @@ SetMirror.prototype.values = function(opt_limit) {
return %GetWeakSetValues(this.value_, opt_limit || 0); return %GetWeakSetValues(this.value_, opt_limit || 0);
} }
var iter = %_CallFunction(this.value_, builtins.SetValues); var iter = %_CallFunction(this.value_, builtins.$setValues);
return IteratorGetValues_(iter, builtins.SetIteratorNextJS, opt_limit); return IteratorGetValues_(iter, builtins.$setIteratorNext, opt_limit);
}; };
@ -1447,11 +1447,11 @@ inherits(IteratorMirror, ObjectMirror);
IteratorMirror.prototype.preview = function(opt_limit) { IteratorMirror.prototype.preview = function(opt_limit) {
if (IS_MAP_ITERATOR(this.value_)) { if (IS_MAP_ITERATOR(this.value_)) {
return IteratorGetValues_(%MapIteratorClone(this.value_), return IteratorGetValues_(%MapIteratorClone(this.value_),
builtins.MapIteratorNextJS, builtins.$mapIteratorNext,
opt_limit); opt_limit);
} else if (IS_SET_ITERATOR(this.value_)) { } else if (IS_SET_ITERATOR(this.value_)) {
return IteratorGetValues_(%SetIteratorClone(this.value_), return IteratorGetValues_(%SetIteratorClone(this.value_),
builtins.SetIteratorNextJS, builtins.$setIteratorNext,
opt_limit); opt_limit);
} }
}; };

View File

@ -5605,7 +5605,7 @@ Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start,
int cooked_idx = function_state_->NextMaterializedLiteralIndex(); int cooked_idx = function_state_->NextMaterializedLiteralIndex();
int raw_idx = function_state_->NextMaterializedLiteralIndex(); int raw_idx = function_state_->NextMaterializedLiteralIndex();
// GetTemplateCallSite // $getTemplateCallSite
ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone()); ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone());
args->Add(factory()->NewArrayLiteral( args->Add(factory()->NewArrayLiteral(
const_cast<ZoneList<Expression*>*>(cooked_strings), const_cast<ZoneList<Expression*>*>(cooked_strings),

View File

@ -7,7 +7,6 @@
// This file relies on the fact that the following declaration has been made // This file relies on the fact that the following declaration has been made
// in runtime.js: // in runtime.js:
// var $Object = global.Object // var $Object = global.Object
// var $WeakMap = global.WeakMap
// For bootstrapper. // For bootstrapper.

View File

@ -2,18 +2,19 @@
// 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.
"use strict";
// Called from a desugaring in the parser. // Called from a desugaring in the parser.
var GetTemplateCallSite;
var $getTemplateCallSite;
(function() { (function() {
"use strict";
%CheckIsBootstrapping(); %CheckIsBootstrapping();
var callSiteCache = new $Map; var callSiteCache = new global.Map;
var mapGetFn = $Map.prototype.get; var mapGetFn = global.Map.prototype.get;
var mapSetFn = $Map.prototype.set; var mapSetFn = global.Map.prototype.set;
function SameCallSiteElements(rawStrings, other) { function SameCallSiteElements(rawStrings, other) {
@ -58,7 +59,7 @@ function SetCachedCallSite(siteObj, hash) {
} }
GetTemplateCallSite = function(siteObj, rawStrings, hash) { $getTemplateCallSite = function(siteObj, rawStrings, hash) {
var cached = GetCachedCallSite(rawStrings, hash); var cached = GetCachedCallSite(rawStrings, hash);
if (!IS_UNDEFINED(cached)) return cached; if (!IS_UNDEFINED(cached)) return cached;

View File

@ -2,15 +2,15 @@
// 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.
(function() {
"use strict"; "use strict";
// This file relies on the fact that the following declaration has been made %CheckIsBootstrapping();
// in runtime.js:
// var $Array = global.Array;
var $WeakMap = global.WeakMap;
var $WeakSet = global.WeakSet;
var GlobalObject = global.Object;
var GlobalWeakMap = global.WeakMap;
var GlobalWeakSet = global.WeakSet;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Harmony WeakMap // Harmony WeakMap
@ -81,27 +81,21 @@ function WeakMapDelete(key) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function SetUpWeakMap() { %SetCode(GlobalWeakMap, WeakMapConstructor);
%CheckIsBootstrapping(); %FunctionSetLength(GlobalWeakMap, 0);
%FunctionSetPrototype(GlobalWeakMap, new GlobalObject());
%AddNamedProperty(GlobalWeakMap.prototype, "constructor", GlobalWeakMap,
DONT_ENUM);
%AddNamedProperty(GlobalWeakMap.prototype, symbolToStringTag, "WeakMap",
DONT_ENUM | READ_ONLY);
%SetCode($WeakMap, WeakMapConstructor); // Set up the non-enumerable functions on the WeakMap prototype object.
%FunctionSetLength($WeakMap, 0); InstallFunctions(GlobalWeakMap.prototype, DONT_ENUM, [
%FunctionSetPrototype($WeakMap, new $Object());
%AddNamedProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM);
%AddNamedProperty(
$WeakMap.prototype, symbolToStringTag, "WeakMap", DONT_ENUM | READ_ONLY);
// Set up the non-enumerable functions on the WeakMap prototype object.
InstallFunctions($WeakMap.prototype, DONT_ENUM, [
"get", WeakMapGet, "get", WeakMapGet,
"set", WeakMapSet, "set", WeakMapSet,
"has", WeakMapHas, "has", WeakMapHas,
"delete", WeakMapDelete "delete", WeakMapDelete
]); ]);
}
SetUpWeakMap();
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Harmony WeakSet // Harmony WeakSet
@ -159,22 +153,19 @@ function WeakSetDelete(value) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function SetUpWeakSet() { %SetCode(GlobalWeakSet, WeakSetConstructor);
%CheckIsBootstrapping(); %FunctionSetLength(GlobalWeakSet, 0);
%FunctionSetPrototype(GlobalWeakSet, new GlobalObject());
%AddNamedProperty(GlobalWeakSet.prototype, "constructor", GlobalWeakSet,
DONT_ENUM);
%AddNamedProperty(GlobalWeakSet.prototype, symbolToStringTag, "WeakSet",
DONT_ENUM | READ_ONLY);
%SetCode($WeakSet, WeakSetConstructor); // Set up the non-enumerable functions on the WeakSet prototype object.
%FunctionSetLength($WeakSet, 0); InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [
%FunctionSetPrototype($WeakSet, new $Object());
%AddNamedProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM);
%AddNamedProperty(
$WeakSet.prototype, symbolToStringTag, "WeakSet", DONT_ENUM | READ_ONLY);
// Set up the non-enumerable functions on the WeakSet prototype object.
InstallFunctions($WeakSet.prototype, DONT_ENUM, [
"add", WeakSetAdd, "add", WeakSetAdd,
"has", WeakSetHas, "has", WeakSetHas,
"delete", WeakSetDelete "delete", WeakSetDelete
]); ]);
}
SetUpWeakSet(); })();