Commit 8b57281f authored by Jaroslav Sevcik's avatar Jaroslav Sevcik Committed by Commit Bot

[builtins] Port Map.prototype.set to CSA.

Bug: v8:5717
Change-Id: I2c3304070529272e84060bd625bf52a1a91203b5
Reviewed-on: https://chromium-review.googlesource.com/581490Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46827}
parent 5520cae3
......@@ -3020,6 +3020,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallFunction(prototype, "get", Builtins::kMapGet, 1, true);
native_context()->set_map_get(*map_get);
Handle<JSFunction> map_set =
SimpleInstallFunction(prototype, "set", Builtins::kMapSet, 2, true);
native_context()->set_map_set(*map_set);
Handle<JSFunction> map_has =
SimpleInstallFunction(prototype, "has", Builtins::kMapHas, 1, true);
native_context()->set_map_has(*map_has);
......
This diff is collapsed.
......@@ -577,6 +577,7 @@ namespace internal {
/* Map */ \
TFS(MapLookupHashIndex, kTable, kKey) \
TFJ(MapConstructor, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
TFJ(MapSet, 2, kKey, kValue) \
TFJ(MapGet, 1, kKey) \
TFJ(MapHas, 1, kKey) \
CPP(MapClear) \
......
......@@ -192,53 +192,6 @@ DEFINE_METHODS(
DEFINE_METHODS(
GlobalMap.prototype,
{
set(key, value) {
if (!IS_MAP(this)) {
throw %make_type_error(kIncompatibleMethodReceiver,
'Map.prototype.set', this);
}
// Normalize -0 to +0 as required by the spec.
// Even though we use SameValueZero as the comparison for the keys we don't
// want to ever store -0 as the key since the key is directly exposed when
// doing iteration.
if (key === 0) {
key = 0;
}
var table = %_JSCollectionGetTable(this);
var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
var hash = GetHash(key);
var entry = MapFindEntry(table, numBuckets, key, hash);
if (entry !== NOT_FOUND) {
var existingIndex = ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets);
FIXED_ARRAY_SET(table, existingIndex + 1, value);
return this;
}
var nof = ORDERED_HASH_TABLE_ELEMENT_COUNT(table);
var nod = ORDERED_HASH_TABLE_DELETED_COUNT(table);
var capacity = numBuckets << 1;
if ((nof + nod) >= capacity) {
// Need to grow, bail out to runtime.
%MapGrow(this);
// Re-load state from the grown backing store.
table = %_JSCollectionGetTable(this);
numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
nof = ORDERED_HASH_TABLE_ELEMENT_COUNT(table);
nod = ORDERED_HASH_TABLE_DELETED_COUNT(table);
}
entry = nof + nod;
var index = ORDERED_HASH_MAP_ENTRY_TO_INDEX(entry, numBuckets);
var bucket = ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets);
var chainEntry = ORDERED_HASH_TABLE_BUCKET_AT(table, bucket);
ORDERED_HASH_TABLE_SET_BUCKET_AT(table, bucket, entry);
ORDERED_HASH_TABLE_SET_ELEMENT_COUNT(table, nof + 1);
FIXED_ARRAY_SET(table, index, key);
FIXED_ARRAY_SET(table, index + 1, value);
FIXED_ARRAY_SET(table, index + 2, chainEntry);
return this;
}
delete(key) {
if (!IS_MAP(this)) {
throw %make_type_error(kIncompatibleMethodReceiver,
......@@ -267,7 +220,6 @@ DEFINE_METHODS(
// Exports
%InstallToContext([
"map_set", GlobalMap.prototype.set,
"map_delete", GlobalMap.prototype.delete,
"set_add", GlobalSet.prototype.add,
"set_delete", GlobalSet.prototype.delete,
......
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