Simplify usage of runtime hashing functions in weak-collection.js

This also removes the IS_GLOBAL macro from macros.py, which did
not work correctly for Remote objects/contexts.

Bug: v8:6413
Change-Id: I90690bdd0d8e8fed581bc4c9f5c60168d785f096
Reviewed-on: https://chromium-review.googlesource.com/633872
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47585}
This commit is contained in:
Adam Klein 2017-08-24 15:49:29 -07:00 committed by Commit Bot
parent 46cb812fa1
commit f9a3a5af2a
3 changed files with 5 additions and 23 deletions

View File

@ -51,7 +51,6 @@ macro IS_DATE(arg) = (%IsDate(arg));
macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error'); macro IS_ERROR(arg) = (%_ClassOf(arg) === 'Error');
macro IS_FUNCTION(arg) = (%IsFunction(arg)); macro IS_FUNCTION(arg) = (%IsFunction(arg));
macro IS_GENERATOR(arg) = (%_ClassOf(arg) === 'Generator'); macro IS_GENERATOR(arg) = (%_ClassOf(arg) === 'Generator');
macro IS_GLOBAL(arg) = (%_ClassOf(arg) === 'global');
macro IS_MAP(arg) = (%_IsJSMap(arg)); macro IS_MAP(arg) = (%_IsJSMap(arg));
macro IS_MAP_ITERATOR(arg) = (%_ClassOf(arg) === 'Map Iterator'); macro IS_MAP_ITERATOR(arg) = (%_ClassOf(arg) === 'Map Iterator');
macro IS_NULL(arg) = (arg === null); macro IS_NULL(arg) = (arg === null);

View File

@ -15,23 +15,6 @@ var GlobalWeakMap = global.WeakMap;
var GlobalWeakSet = global.WeakSet; var GlobalWeakSet = global.WeakSet;
var MathRandom = global.Math.random; var MathRandom = global.Math.random;
// -------------------------------------------------------------------
function GetExistingHash(key) {
if (IS_RECEIVER(key) && !IS_PROXY(key) && !IS_GLOBAL(key)) {
return %GetExistingHash(key);
}
return %GenericHash(key);
}
%SetForceInlineFlag(GetExistingHash);
function GetHash(key) {
return %GenericHash(key);
}
%SetForceInlineFlag(GetHash);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Harmony WeakMap // Harmony WeakMap
@ -67,7 +50,7 @@ DEFINE_METHODS(
'WeakMap.prototype.set', this); 'WeakMap.prototype.set', this);
} }
if (!IS_RECEIVER(key)) throw %make_type_error(kInvalidWeakMapKey); if (!IS_RECEIVER(key)) throw %make_type_error(kInvalidWeakMapKey);
return %WeakCollectionSet(this, key, value, GetHash(key)); return %WeakCollectionSet(this, key, value, %GenericHash(key));
} }
delete(key) { delete(key) {
@ -76,7 +59,7 @@ DEFINE_METHODS(
'WeakMap.prototype.delete', this); 'WeakMap.prototype.delete', this);
} }
if (!IS_RECEIVER(key)) return false; if (!IS_RECEIVER(key)) return false;
var hash = GetExistingHash(key); var hash = %GetExistingHash(key);
if (IS_UNDEFINED(hash)) return false; if (IS_UNDEFINED(hash)) return false;
return %WeakCollectionDelete(this, key, hash); return %WeakCollectionDelete(this, key, hash);
} }
@ -120,7 +103,7 @@ DEFINE_METHODS(
'WeakSet.prototype.add', this); 'WeakSet.prototype.add', this);
} }
if (!IS_RECEIVER(value)) throw %make_type_error(kInvalidWeakSetValue); if (!IS_RECEIVER(value)) throw %make_type_error(kInvalidWeakSetValue);
return %WeakCollectionSet(this, value, true, GetHash(value)); return %WeakCollectionSet(this, value, true, %GenericHash(value));
} }
delete(value) { delete(value) {
@ -129,7 +112,7 @@ DEFINE_METHODS(
'WeakSet.prototype.delete', this); 'WeakSet.prototype.delete', this);
} }
if (!IS_RECEIVER(value)) return false; if (!IS_RECEIVER(value)) return false;
var hash = GetExistingHash(value); var hash = %GetExistingHash(value);
if (IS_UNDEFINED(hash)) return false; if (IS_UNDEFINED(hash)) return false;
return %WeakCollectionDelete(this, value, hash); return %WeakCollectionDelete(this, value, hash);
} }

View File

@ -20,7 +20,7 @@ RUNTIME_FUNCTION(Runtime_TheHole) {
RUNTIME_FUNCTION(Runtime_GetExistingHash) { RUNTIME_FUNCTION(Runtime_GetExistingHash) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
return object->GetHash(); return object->GetHash();
} }