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:
parent
d3b788df0a
commit
05bfdd866a
@ -244,7 +244,7 @@ class AstValue : public ZoneObject {
|
||||
F(dot_result, ".result") \
|
||||
F(empty, "") \
|
||||
F(eval, "eval") \
|
||||
F(get_template_callsite, "GetTemplateCallSite") \
|
||||
F(get_template_callsite, "$getTemplateCallSite") \
|
||||
F(initialize_const_global, "initializeConstGlobal") \
|
||||
F(initialize_var_global, "initializeVarGlobal") \
|
||||
F(is_construct_call, "_IsConstructCall") \
|
||||
|
@ -2,14 +2,22 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
var $mapEntries;
|
||||
var $mapIteratorNext;
|
||||
var $setIteratorNext;
|
||||
var $setValues;
|
||||
|
||||
(function() {
|
||||
|
||||
"use strict";
|
||||
|
||||
%CheckIsBootstrapping();
|
||||
|
||||
// This file relies on the fact that the following declaration has been made
|
||||
// in runtime.js:
|
||||
// var $Set = global.Set;
|
||||
// var $Map = global.Map;
|
||||
var GlobalMap = global.Map;
|
||||
var GlobalObject = global.Object;
|
||||
var GlobalSet = global.Set;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function SetIteratorConstructor(set, kind) {
|
||||
%SetIteratorInitialize(this, set, kind);
|
||||
@ -63,42 +71,33 @@ function SetValues() {
|
||||
return new SetIterator(this, ITERATOR_KIND_VALUES);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function SetUpSetIterator() {
|
||||
%CheckIsBootstrapping();
|
||||
%SetCode(SetIterator, SetIteratorConstructor);
|
||||
%FunctionSetPrototype(SetIterator, new GlobalObject());
|
||||
%FunctionSetInstanceClassName(SetIterator, 'Set Iterator');
|
||||
InstallFunctions(SetIterator.prototype, DONT_ENUM, [
|
||||
'next', SetIteratorNextJS
|
||||
]);
|
||||
|
||||
%SetCode(SetIterator, SetIteratorConstructor);
|
||||
%FunctionSetPrototype(SetIterator, new $Object());
|
||||
%FunctionSetInstanceClassName(SetIterator, 'Set Iterator');
|
||||
InstallFunctions(SetIterator.prototype, DONT_ENUM, [
|
||||
'next', SetIteratorNextJS
|
||||
]);
|
||||
%FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]');
|
||||
%AddNamedProperty(SetIterator.prototype, symbolIterator,
|
||||
SetIteratorSymbolIterator, DONT_ENUM);
|
||||
%AddNamedProperty(SetIterator.prototype, symbolToStringTag,
|
||||
"Set Iterator", READ_ONLY | DONT_ENUM);
|
||||
|
||||
%FunctionSetName(SetIteratorSymbolIterator, '[Symbol.iterator]');
|
||||
%AddNamedProperty(SetIterator.prototype, symbolIterator,
|
||||
SetIteratorSymbolIterator, DONT_ENUM);
|
||||
%AddNamedProperty(SetIterator.prototype, symbolToStringTag,
|
||||
"Set Iterator", READ_ONLY | DONT_ENUM);
|
||||
}
|
||||
InstallFunctions(GlobalSet.prototype, DONT_ENUM, [
|
||||
'entries', SetEntries,
|
||||
'keys', SetValues,
|
||||
'values', SetValues
|
||||
]);
|
||||
|
||||
SetUpSetIterator();
|
||||
|
||||
|
||||
function ExtendSetPrototype() {
|
||||
%CheckIsBootstrapping();
|
||||
|
||||
InstallFunctions($Set.prototype, DONT_ENUM, [
|
||||
'entries', SetEntries,
|
||||
'keys', SetValues,
|
||||
'values', SetValues
|
||||
]);
|
||||
|
||||
%AddNamedProperty($Set.prototype, symbolIterator, SetValues, DONT_ENUM);
|
||||
}
|
||||
|
||||
ExtendSetPrototype();
|
||||
%AddNamedProperty(GlobalSet.prototype, symbolIterator, SetValues, DONT_ENUM);
|
||||
|
||||
$setIteratorNext = SetIteratorNextJS;
|
||||
$setValues = SetValues;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function MapIteratorConstructor(map, kind) {
|
||||
%MapIteratorInitialize(this, map, kind);
|
||||
@ -162,37 +161,31 @@ function MapValues() {
|
||||
return new MapIterator(this, ITERATOR_KIND_VALUES);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function SetUpMapIterator() {
|
||||
%CheckIsBootstrapping();
|
||||
%SetCode(MapIterator, MapIteratorConstructor);
|
||||
%FunctionSetPrototype(MapIterator, new GlobalObject());
|
||||
%FunctionSetInstanceClassName(MapIterator, 'Map Iterator');
|
||||
InstallFunctions(MapIterator.prototype, DONT_ENUM, [
|
||||
'next', MapIteratorNextJS
|
||||
]);
|
||||
|
||||
%SetCode(MapIterator, MapIteratorConstructor);
|
||||
%FunctionSetPrototype(MapIterator, new $Object());
|
||||
%FunctionSetInstanceClassName(MapIterator, 'Map Iterator');
|
||||
InstallFunctions(MapIterator.prototype, DONT_ENUM, [
|
||||
'next', MapIteratorNextJS
|
||||
]);
|
||||
|
||||
%FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
|
||||
%AddNamedProperty(MapIterator.prototype, symbolIterator,
|
||||
MapIteratorSymbolIterator, DONT_ENUM);
|
||||
%AddNamedProperty(MapIterator.prototype, symbolToStringTag,
|
||||
"Map Iterator", READ_ONLY | DONT_ENUM);
|
||||
}
|
||||
|
||||
SetUpMapIterator();
|
||||
%FunctionSetName(MapIteratorSymbolIterator, '[Symbol.iterator]');
|
||||
%AddNamedProperty(MapIterator.prototype, symbolIterator,
|
||||
MapIteratorSymbolIterator, DONT_ENUM);
|
||||
%AddNamedProperty(MapIterator.prototype, symbolToStringTag,
|
||||
"Map Iterator", READ_ONLY | DONT_ENUM);
|
||||
|
||||
|
||||
function ExtendMapPrototype() {
|
||||
%CheckIsBootstrapping();
|
||||
InstallFunctions(GlobalMap.prototype, DONT_ENUM, [
|
||||
'entries', MapEntries,
|
||||
'keys', MapKeys,
|
||||
'values', MapValues
|
||||
]);
|
||||
|
||||
InstallFunctions($Map.prototype, DONT_ENUM, [
|
||||
'entries', MapEntries,
|
||||
'keys', MapKeys,
|
||||
'values', MapValues
|
||||
]);
|
||||
%AddNamedProperty(GlobalMap.prototype, symbolIterator, MapEntries, DONT_ENUM);
|
||||
|
||||
%AddNamedProperty($Map.prototype, symbolIterator, MapEntries, DONT_ENUM);
|
||||
}
|
||||
$mapEntries = MapEntries;
|
||||
$mapIteratorNext = MapIteratorNextJS;
|
||||
|
||||
ExtendMapPrototype();
|
||||
})();
|
||||
|
@ -2,20 +2,17 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// 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() {
|
||||
|
||||
"use strict";
|
||||
|
||||
%CheckIsBootstrapping();
|
||||
|
||||
var GlobalMap = global.Map;
|
||||
var GlobalObject = global.Object;
|
||||
var GlobalSet = global.Set;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function HashToEntry(table, hash, numBuckets) {
|
||||
var bucket = ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets);
|
||||
@ -230,19 +227,20 @@ function SetForEach(f, receiver) {
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
%SetCode($Set, SetConstructor);
|
||||
%FunctionSetLength($Set, 0);
|
||||
%FunctionSetPrototype($Set, new $Object());
|
||||
%AddNamedProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
|
||||
%AddNamedProperty(
|
||||
$Set.prototype, symbolToStringTag, "Set", DONT_ENUM | READ_ONLY);
|
||||
%SetCode(GlobalSet, SetConstructor);
|
||||
%FunctionSetLength(GlobalSet, 0);
|
||||
%FunctionSetPrototype(GlobalSet, new GlobalObject());
|
||||
%AddNamedProperty(GlobalSet.prototype, "constructor", GlobalSet, DONT_ENUM);
|
||||
%AddNamedProperty(GlobalSet.prototype, symbolToStringTag, "Set",
|
||||
DONT_ENUM | READ_ONLY);
|
||||
|
||||
%FunctionSetLength(SetForEach, 1);
|
||||
|
||||
// Set up the non-enumerable functions on the Set prototype object.
|
||||
InstallGetter($Set.prototype, "size", SetGetSize);
|
||||
InstallFunctions($Set.prototype, DONT_ENUM, [
|
||||
InstallGetter(GlobalSet.prototype, "size", SetGetSize);
|
||||
InstallFunctions(GlobalSet.prototype, DONT_ENUM, [
|
||||
"add", SetAdd,
|
||||
"has", SetHas,
|
||||
"delete", SetDelete,
|
||||
@ -417,19 +415,20 @@ function MapForEach(f, receiver) {
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
%SetCode($Map, MapConstructor);
|
||||
%FunctionSetLength($Map, 0);
|
||||
%FunctionSetPrototype($Map, new $Object());
|
||||
%AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
|
||||
%SetCode(GlobalMap, MapConstructor);
|
||||
%FunctionSetLength(GlobalMap, 0);
|
||||
%FunctionSetPrototype(GlobalMap, new GlobalObject());
|
||||
%AddNamedProperty(GlobalMap.prototype, "constructor", GlobalMap, DONT_ENUM);
|
||||
%AddNamedProperty(
|
||||
$Map.prototype, symbolToStringTag, "Map", DONT_ENUM | READ_ONLY);
|
||||
GlobalMap.prototype, symbolToStringTag, "Map", DONT_ENUM | READ_ONLY);
|
||||
|
||||
%FunctionSetLength(MapForEach, 1);
|
||||
|
||||
// Set up the non-enumerable functions on the Map prototype object.
|
||||
InstallGetter($Map.prototype, "size", MapGetSize);
|
||||
InstallFunctions($Map.prototype, DONT_ENUM, [
|
||||
InstallGetter(GlobalMap.prototype, "size", MapGetSize);
|
||||
InstallFunctions(GlobalMap.prototype, DONT_ENUM, [
|
||||
"get", MapGet,
|
||||
"set", MapSet,
|
||||
"has", MapHas,
|
||||
|
@ -1384,7 +1384,7 @@ MapMirror.prototype.entries = function(opt_limit) {
|
||||
return result;
|
||||
}
|
||||
|
||||
var iter = %_CallFunction(this.value_, builtins.MapEntries);
|
||||
var iter = %_CallFunction(this.value_, builtins.$mapEntries);
|
||||
var next;
|
||||
while ((!opt_limit || result.length < opt_limit) &&
|
||||
!(next = iter.next()).done) {
|
||||
@ -1426,8 +1426,8 @@ SetMirror.prototype.values = function(opt_limit) {
|
||||
return %GetWeakSetValues(this.value_, opt_limit || 0);
|
||||
}
|
||||
|
||||
var iter = %_CallFunction(this.value_, builtins.SetValues);
|
||||
return IteratorGetValues_(iter, builtins.SetIteratorNextJS, opt_limit);
|
||||
var iter = %_CallFunction(this.value_, builtins.$setValues);
|
||||
return IteratorGetValues_(iter, builtins.$setIteratorNext, opt_limit);
|
||||
};
|
||||
|
||||
|
||||
@ -1447,11 +1447,11 @@ inherits(IteratorMirror, ObjectMirror);
|
||||
IteratorMirror.prototype.preview = function(opt_limit) {
|
||||
if (IS_MAP_ITERATOR(this.value_)) {
|
||||
return IteratorGetValues_(%MapIteratorClone(this.value_),
|
||||
builtins.MapIteratorNextJS,
|
||||
builtins.$mapIteratorNext,
|
||||
opt_limit);
|
||||
} else if (IS_SET_ITERATOR(this.value_)) {
|
||||
return IteratorGetValues_(%SetIteratorClone(this.value_),
|
||||
builtins.SetIteratorNextJS,
|
||||
builtins.$setIteratorNext,
|
||||
opt_limit);
|
||||
}
|
||||
};
|
||||
|
@ -5605,7 +5605,7 @@ Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start,
|
||||
int cooked_idx = function_state_->NextMaterializedLiteralIndex();
|
||||
int raw_idx = function_state_->NextMaterializedLiteralIndex();
|
||||
|
||||
// GetTemplateCallSite
|
||||
// $getTemplateCallSite
|
||||
ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone());
|
||||
args->Add(factory()->NewArrayLiteral(
|
||||
const_cast<ZoneList<Expression*>*>(cooked_strings),
|
||||
|
@ -7,7 +7,6 @@
|
||||
// This file relies on the fact that the following declaration has been made
|
||||
// in runtime.js:
|
||||
// var $Object = global.Object
|
||||
// var $WeakMap = global.WeakMap
|
||||
|
||||
// For bootstrapper.
|
||||
|
||||
|
@ -2,18 +2,19 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
"use strict";
|
||||
|
||||
// Called from a desugaring in the parser.
|
||||
var GetTemplateCallSite;
|
||||
|
||||
var $getTemplateCallSite;
|
||||
|
||||
(function() {
|
||||
|
||||
"use strict";
|
||||
|
||||
%CheckIsBootstrapping();
|
||||
|
||||
var callSiteCache = new $Map;
|
||||
var mapGetFn = $Map.prototype.get;
|
||||
var mapSetFn = $Map.prototype.set;
|
||||
var callSiteCache = new global.Map;
|
||||
var mapGetFn = global.Map.prototype.get;
|
||||
var mapSetFn = global.Map.prototype.set;
|
||||
|
||||
|
||||
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);
|
||||
|
||||
if (!IS_UNDEFINED(cached)) return cached;
|
||||
|
@ -2,15 +2,15 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
(function() {
|
||||
|
||||
"use strict";
|
||||
|
||||
// This file relies on the fact that the following declaration has been made
|
||||
// in runtime.js:
|
||||
// var $Array = global.Array;
|
||||
|
||||
var $WeakMap = global.WeakMap;
|
||||
var $WeakSet = global.WeakSet;
|
||||
%CheckIsBootstrapping();
|
||||
|
||||
var GlobalObject = global.Object;
|
||||
var GlobalWeakMap = global.WeakMap;
|
||||
var GlobalWeakSet = global.WeakSet;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Harmony WeakMap
|
||||
@ -81,27 +81,21 @@ function WeakMapDelete(key) {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function SetUpWeakMap() {
|
||||
%CheckIsBootstrapping();
|
||||
|
||||
%SetCode($WeakMap, WeakMapConstructor);
|
||||
%FunctionSetLength($WeakMap, 0);
|
||||
%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,
|
||||
"set", WeakMapSet,
|
||||
"has", WeakMapHas,
|
||||
"delete", WeakMapDelete
|
||||
]);
|
||||
}
|
||||
|
||||
SetUpWeakMap();
|
||||
%SetCode(GlobalWeakMap, WeakMapConstructor);
|
||||
%FunctionSetLength(GlobalWeakMap, 0);
|
||||
%FunctionSetPrototype(GlobalWeakMap, new GlobalObject());
|
||||
%AddNamedProperty(GlobalWeakMap.prototype, "constructor", GlobalWeakMap,
|
||||
DONT_ENUM);
|
||||
%AddNamedProperty(GlobalWeakMap.prototype, symbolToStringTag, "WeakMap",
|
||||
DONT_ENUM | READ_ONLY);
|
||||
|
||||
// Set up the non-enumerable functions on the WeakMap prototype object.
|
||||
InstallFunctions(GlobalWeakMap.prototype, DONT_ENUM, [
|
||||
"get", WeakMapGet,
|
||||
"set", WeakMapSet,
|
||||
"has", WeakMapHas,
|
||||
"delete", WeakMapDelete
|
||||
]);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Harmony WeakSet
|
||||
@ -159,22 +153,19 @@ function WeakSetDelete(value) {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function SetUpWeakSet() {
|
||||
%CheckIsBootstrapping();
|
||||
%SetCode(GlobalWeakSet, WeakSetConstructor);
|
||||
%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);
|
||||
%FunctionSetLength($WeakSet, 0);
|
||||
%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(GlobalWeakSet.prototype, DONT_ENUM, [
|
||||
"add", WeakSetAdd,
|
||||
"has", WeakSetHas,
|
||||
"delete", WeakSetDelete
|
||||
]);
|
||||
|
||||
// Set up the non-enumerable functions on the WeakSet prototype object.
|
||||
InstallFunctions($WeakSet.prototype, DONT_ENUM, [
|
||||
"add", WeakSetAdd,
|
||||
"has", WeakSetHas,
|
||||
"delete", WeakSetDelete
|
||||
]);
|
||||
}
|
||||
|
||||
SetUpWeakSet();
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user