[runtime] Remove %AddNamedProperty and %AddElement
%AddNamedProperty was only used by regression tests, and is easily replaced by Object.defineProperty (or deleted, in the case of a cctest that was designed to test it directly). %AddElement was unused (probably due to the death of array.js). Bug: v8:7624 Change-Id: Icc17fd7a7419aa649275414a351f176f104040e2 Reviewed-on: https://chromium-review.googlesource.com/c/1387990 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Adam Klein <adamk@chromium.org> Cr-Commit-Position: refs/heads/master@{#58448}
This commit is contained in:
parent
ceaaaf14a2
commit
43fff3d7b1
@ -543,59 +543,6 @@ RUNTIME_FUNCTION(Runtime_GetProperty) {
|
|||||||
isolate, Runtime::GetObjectProperty(isolate, receiver_obj, key_obj));
|
isolate, Runtime::GetObjectProperty(isolate, receiver_obj, key_obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
RUNTIME_FUNCTION(Runtime_AddNamedProperty) {
|
|
||||||
HandleScope scope(isolate);
|
|
||||||
DCHECK_EQ(4, args.length());
|
|
||||||
|
|
||||||
CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
|
|
||||||
CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
|
|
||||||
CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
|
|
||||||
CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
uint32_t index = 0;
|
|
||||||
DCHECK(!name->ToArrayIndex(&index));
|
|
||||||
LookupIterator it(object, name, object, LookupIterator::OWN_SKIP_INTERCEPTOR);
|
|
||||||
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
|
|
||||||
if (maybe.IsNothing()) return ReadOnlyRoots(isolate).exception();
|
|
||||||
DCHECK(!it.IsFound());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RETURN_RESULT_OR_FAILURE(isolate, JSObject::SetOwnPropertyIgnoreAttributes(
|
|
||||||
object, name, value, attrs));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Adds an element to an array.
|
|
||||||
// This is used to create an indexed data property into an array.
|
|
||||||
RUNTIME_FUNCTION(Runtime_AddElement) {
|
|
||||||
HandleScope scope(isolate);
|
|
||||||
DCHECK_EQ(3, args.length());
|
|
||||||
|
|
||||||
CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
|
|
||||||
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
|
|
||||||
CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
|
|
||||||
|
|
||||||
uint32_t index = 0;
|
|
||||||
CHECK(key->ToArrayIndex(&index));
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
LookupIterator it(isolate, object, index, object,
|
|
||||||
LookupIterator::OWN_SKIP_INTERCEPTOR);
|
|
||||||
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
|
|
||||||
if (maybe.IsNothing()) return ReadOnlyRoots(isolate).exception();
|
|
||||||
DCHECK(!it.IsFound());
|
|
||||||
|
|
||||||
if (object->IsJSArray()) {
|
|
||||||
Handle<JSArray> array = Handle<JSArray>::cast(object);
|
|
||||||
DCHECK(!JSArray::WouldChangeReadOnlyLength(array, index));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RETURN_RESULT_OR_FAILURE(isolate, JSObject::SetOwnElementIgnoreAttributes(
|
|
||||||
object, index, value, NONE));
|
|
||||||
}
|
|
||||||
|
|
||||||
RUNTIME_FUNCTION(Runtime_SetKeyedProperty) {
|
RUNTIME_FUNCTION(Runtime_SetKeyedProperty) {
|
||||||
HandleScope scope(isolate);
|
HandleScope scope(isolate);
|
||||||
DCHECK_EQ(4, args.length());
|
DCHECK_EQ(4, args.length());
|
||||||
|
@ -277,8 +277,6 @@ namespace internal {
|
|||||||
|
|
||||||
#define FOR_EACH_INTRINSIC_OBJECT(F, I) \
|
#define FOR_EACH_INTRINSIC_OBJECT(F, I) \
|
||||||
F(AddDictionaryProperty, 3, 1) \
|
F(AddDictionaryProperty, 3, 1) \
|
||||||
F(AddElement, 3, 1) \
|
|
||||||
F(AddNamedProperty, 4, 1) \
|
|
||||||
F(AddPrivateField, 3, 1) \
|
F(AddPrivateField, 3, 1) \
|
||||||
F(AllocateHeapNumber, 0, 1) \
|
F(AllocateHeapNumber, 0, 1) \
|
||||||
F(ClassOf, 1, 1) \
|
F(ClassOf, 1, 1) \
|
||||||
|
@ -23503,7 +23503,6 @@ TEST(AccessCheckThrows) {
|
|||||||
CheckCorrectThrow("has_own_property(other, 'x')");
|
CheckCorrectThrow("has_own_property(other, 'x')");
|
||||||
CheckCorrectThrow("%GetProperty(other, 'x')");
|
CheckCorrectThrow("%GetProperty(other, 'x')");
|
||||||
CheckCorrectThrow("%SetKeyedProperty(other, 'x', 'foo', 0)");
|
CheckCorrectThrow("%SetKeyedProperty(other, 'x', 'foo', 0)");
|
||||||
CheckCorrectThrow("%AddNamedProperty(other, 'x', 'foo', 1)");
|
|
||||||
CheckCorrectThrow("%SetNamedProperty(other, 'y', 'foo', 1)");
|
CheckCorrectThrow("%SetNamedProperty(other, 'y', 'foo', 1)");
|
||||||
STATIC_ASSERT(static_cast<int>(i::LanguageMode::kSloppy) == 0);
|
STATIC_ASSERT(static_cast<int>(i::LanguageMode::kSloppy) == 0);
|
||||||
STATIC_ASSERT(static_cast<int>(i::LanguageMode::kStrict) == 1);
|
STATIC_ASSERT(static_cast<int>(i::LanguageMode::kStrict) == 1);
|
||||||
|
@ -32,44 +32,53 @@
|
|||||||
var NONE = 0;
|
var NONE = 0;
|
||||||
var READ_ONLY = 1;
|
var READ_ONLY = 1;
|
||||||
|
|
||||||
|
function AddNamedProperty(object, name, value, attrs) {
|
||||||
|
Object.defineProperty(object, name, {
|
||||||
|
value,
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true,
|
||||||
|
writable: (attrs & READ_ONLY) === 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Use DeclareGlobal...
|
// Use DeclareGlobal...
|
||||||
%AddNamedProperty(this.__proto__, "a", 1234, NONE);
|
AddNamedProperty(this.__proto__, "a", 1234, NONE);
|
||||||
assertEquals(1234, a);
|
assertEquals(1234, a);
|
||||||
eval("var a = 5678;");
|
eval("var a = 5678;");
|
||||||
assertEquals(5678, a);
|
assertEquals(5678, a);
|
||||||
|
|
||||||
%AddNamedProperty(this.__proto__, "b", 1234, NONE);
|
AddNamedProperty(this.__proto__, "b", 1234, NONE);
|
||||||
assertEquals(1234, b);
|
assertEquals(1234, b);
|
||||||
eval("var b = 5678;");
|
eval("var b = 5678;");
|
||||||
assertEquals(5678, b);
|
assertEquals(5678, b);
|
||||||
|
|
||||||
%AddNamedProperty(this.__proto__, "c", 1234, READ_ONLY);
|
AddNamedProperty(this.__proto__, "c", 1234, READ_ONLY);
|
||||||
assertEquals(1234, c);
|
assertEquals(1234, c);
|
||||||
eval("var c = 5678;");
|
eval("var c = 5678;");
|
||||||
assertEquals(5678, c);
|
assertEquals(5678, c);
|
||||||
|
|
||||||
%AddNamedProperty(this.__proto__, "d", 1234, READ_ONLY);
|
AddNamedProperty(this.__proto__, "d", 1234, READ_ONLY);
|
||||||
assertEquals(1234, d);
|
assertEquals(1234, d);
|
||||||
eval("var d = 5678;");
|
eval("var d = 5678;");
|
||||||
assertEquals(5678, d);
|
assertEquals(5678, d);
|
||||||
|
|
||||||
// Use DeclareContextSlot...
|
// Use DeclareContextSlot...
|
||||||
%AddNamedProperty(this.__proto__, "x", 1234, NONE);
|
AddNamedProperty(this.__proto__, "x", 1234, NONE);
|
||||||
assertEquals(1234, x);
|
assertEquals(1234, x);
|
||||||
eval("with({}) { var x = 5678; }");
|
eval("with({}) { var x = 5678; }");
|
||||||
assertEquals(5678, x);
|
assertEquals(5678, x);
|
||||||
|
|
||||||
%AddNamedProperty(this.__proto__, "y", 1234, NONE);
|
AddNamedProperty(this.__proto__, "y", 1234, NONE);
|
||||||
assertEquals(1234, y);
|
assertEquals(1234, y);
|
||||||
eval("with({}) { var y = 5678; }");
|
eval("with({}) { var y = 5678; }");
|
||||||
assertEquals(5678, y);
|
assertEquals(5678, y);
|
||||||
|
|
||||||
%AddNamedProperty(this.__proto__, "z", 1234, READ_ONLY);
|
AddNamedProperty(this.__proto__, "z", 1234, READ_ONLY);
|
||||||
assertEquals(1234, z);
|
assertEquals(1234, z);
|
||||||
eval("with({}) { var z = 5678; }");
|
eval("with({}) { var z = 5678; }");
|
||||||
assertEquals(5678, z);
|
assertEquals(5678, z);
|
||||||
|
|
||||||
%AddNamedProperty(this.__proto__, "w", 1234, READ_ONLY);
|
AddNamedProperty(this.__proto__, "w", 1234, READ_ONLY);
|
||||||
assertEquals(1234, w);
|
assertEquals(1234, w);
|
||||||
eval("with({}) { var w = 5678; }");
|
eval("with({}) { var w = 5678; }");
|
||||||
assertEquals(5678, w);
|
assertEquals(5678, w);
|
||||||
|
@ -33,14 +33,23 @@ var READ_ONLY = 1;
|
|||||||
var DONT_ENUM = 2;
|
var DONT_ENUM = 2;
|
||||||
var DONT_DELETE = 4;
|
var DONT_DELETE = 4;
|
||||||
|
|
||||||
|
function AddNamedProperty(object, name, value, attrs) {
|
||||||
|
Object.defineProperty(object, name, {
|
||||||
|
value,
|
||||||
|
configurable: (attrs & DONT_DELETE) === 0,
|
||||||
|
enumerable: (attrs & DONT_ENUM) === 0,
|
||||||
|
writable: (attrs & READ_ONLY) === 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function func1(){}
|
function func1(){}
|
||||||
function func2(){}
|
function func2(){}
|
||||||
|
|
||||||
var object = {__proto__:{}};
|
var object = {__proto__:{}};
|
||||||
%AddNamedProperty(object, "foo", func1, DONT_ENUM | DONT_DELETE);
|
AddNamedProperty(object, "foo", func1, DONT_ENUM | DONT_DELETE);
|
||||||
%AddNamedProperty(object, "bar", func1, DONT_ENUM | READ_ONLY);
|
AddNamedProperty(object, "bar", func1, DONT_ENUM | READ_ONLY);
|
||||||
%AddNamedProperty(object, "baz", func1, DONT_DELETE | READ_ONLY);
|
AddNamedProperty(object, "baz", func1, DONT_DELETE | READ_ONLY);
|
||||||
%AddNamedProperty(object.__proto__, "bif", func1, DONT_ENUM | DONT_DELETE);
|
AddNamedProperty(object.__proto__, "bif", func1, DONT_ENUM | DONT_DELETE);
|
||||||
object.bif = func2;
|
object.bif = func2;
|
||||||
|
|
||||||
function enumerable(obj) {
|
function enumerable(obj) {
|
||||||
|
@ -27,13 +27,16 @@
|
|||||||
|
|
||||||
// Flags: --allow-natives-syntax --expose-gc
|
// Flags: --allow-natives-syntax --expose-gc
|
||||||
|
|
||||||
DontEnum = 2;
|
|
||||||
|
|
||||||
var o = {};
|
var o = {};
|
||||||
%AddNamedProperty(o, "a", 0, DontEnum);
|
Object.defineProperty(o, "a", {
|
||||||
|
value: 0, configurable: true, writable: true, enumerable: false
|
||||||
|
});
|
||||||
|
|
||||||
var o2 = {};
|
var o2 = {};
|
||||||
%AddNamedProperty(o2, "a", 0, DontEnum);
|
Object.defineProperty(o2, "a", {
|
||||||
|
value: 0, configurable: true, writable: true, enumerable: false
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
assertTrue(%HaveSameMap(o, o2));
|
assertTrue(%HaveSameMap(o, o2));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user