From 59525f07dfa4d80f168b33ee6459336bdc1e4184 Mon Sep 17 00:00:00 2001 From: arv Date: Wed, 4 Feb 2015 10:22:23 -0800 Subject: [PATCH] Add macro for getting a PropertyAttributes for the runtime functions Motivation: Cleanup BUG=None R=adamk LOG=N Review URL: https://codereview.chromium.org/897633003 Cr-Commit-Position: refs/heads/master@{#26440} --- src/runtime/runtime-object.cc | 58 ++++++++++++----------------------- src/runtime/runtime-utils.h | 10 ++++++ 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/runtime/runtime-object.cc b/src/runtime/runtime-object.cc index 1d45cb1d11..bde3021df1 100644 --- a/src/runtime/runtime-object.cc +++ b/src/runtime/runtime-object.cc @@ -194,7 +194,7 @@ MaybeHandle Runtime::SetObjectProperty(Isolate* isolate, MaybeHandle Runtime::DefineObjectProperty(Handle js_object, Handle key, Handle value, - PropertyAttributes attr) { + PropertyAttributes attrs) { Isolate* isolate = js_object->GetIsolate(); // Check if the given key is an array index. uint32_t index; @@ -210,19 +210,19 @@ MaybeHandle Runtime::DefineObjectProperty(Handle js_object, return value; } - return JSObject::SetElement(js_object, index, value, attr, SLOPPY, false, + return JSObject::SetElement(js_object, index, value, attrs, SLOPPY, false, DEFINE_PROPERTY); } if (key->IsName()) { Handle name = Handle::cast(key); if (name->AsArrayIndex(&index)) { - return JSObject::SetElement(js_object, index, value, attr, SLOPPY, false, + return JSObject::SetElement(js_object, index, value, attrs, SLOPPY, false, DEFINE_PROPERTY); } else { if (name->IsString()) name = String::Flatten(Handle::cast(name)); return JSObject::SetOwnPropertyIgnoreAttributes(js_object, name, value, - attr); + attrs); } } @@ -233,11 +233,11 @@ MaybeHandle Runtime::DefineObjectProperty(Handle js_object, Handle name = Handle::cast(converted); if (name->AsArrayIndex(&index)) { - return JSObject::SetElement(js_object, index, value, attr, SLOPPY, false, + return JSObject::SetElement(js_object, index, value, attrs, SLOPPY, false, DEFINE_PROPERTY); } else { return JSObject::SetOwnPropertyIgnoreAttributes(js_object, name, value, - attr); + attrs); } } @@ -664,12 +664,7 @@ RUNTIME_FUNCTION(Runtime_AddNamedProperty) { CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); - CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3); - RUNTIME_ASSERT( - (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); - // Compute attributes. - PropertyAttributes attributes = - static_cast(unchecked_attributes); + CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); #ifdef DEBUG uint32_t index = 0; @@ -683,7 +678,7 @@ RUNTIME_FUNCTION(Runtime_AddNamedProperty) { Handle result; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, result, - JSObject::SetOwnPropertyIgnoreAttributes(object, key, value, attributes)); + JSObject::SetOwnPropertyIgnoreAttributes(object, key, value, attrs)); return *result; } @@ -715,20 +710,15 @@ RUNTIME_FUNCTION(Runtime_AddElement) { CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); - CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3); - RUNTIME_ASSERT( - (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); - // Compute attributes. - PropertyAttributes attributes = - static_cast(unchecked_attributes); + CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); uint32_t index = 0; key->ToArrayIndex(&index); Handle result; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, result, JSObject::SetElement(object, index, value, attributes, - SLOPPY, false, DEFINE_PROPERTY)); + isolate, result, JSObject::SetElement(object, index, value, attrs, SLOPPY, + false, DEFINE_PROPERTY)); return *result; } @@ -1037,9 +1027,9 @@ RUNTIME_FUNCTION(Runtime_GetOwnElementNames) { } CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0); - int n = obj->NumberOfOwnElements(static_cast(NONE)); + int n = obj->NumberOfOwnElements(NONE); Handle names = isolate->factory()->NewFixedArray(n); - obj->GetOwnElementKeys(*names, static_cast(NONE)); + obj->GetOwnElementKeys(*names, NONE); return *isolate->factory()->NewJSArrayWithElements(names); } @@ -1444,12 +1434,10 @@ RUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) { RUNTIME_ASSERT(IsValidAccessor(getter)); CONVERT_ARG_HANDLE_CHECKED(Object, setter, 3); RUNTIME_ASSERT(IsValidAccessor(setter)); - CONVERT_SMI_ARG_CHECKED(unchecked, 4); - RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); - PropertyAttributes attr = static_cast(unchecked); + CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 4); RETURN_FAILURE_ON_EXCEPTION( - isolate, JSObject::DefineAccessor(obj, name, getter, setter, attr)); + isolate, JSObject::DefineAccessor(obj, name, getter, setter, attrs)); return isolate->heap()->undefined_value(); } @@ -1466,9 +1454,7 @@ RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) { CONVERT_ARG_HANDLE_CHECKED(JSObject, js_object, 0); CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); CONVERT_ARG_HANDLE_CHECKED(Object, obj_value, 2); - CONVERT_SMI_ARG_CHECKED(unchecked, 3); - RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); - PropertyAttributes attr = static_cast(unchecked); + CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); LookupIterator it(js_object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); if (it.IsFound() && it.state() == LookupIterator::ACCESS_CHECK) { @@ -1487,14 +1473,14 @@ RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) { ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, result, JSObject::SetOwnPropertyIgnoreAttributes( - js_object, name, obj_value, attr, JSObject::DONT_FORCE_FIELD)); + js_object, name, obj_value, attrs, JSObject::DONT_FORCE_FIELD)); return *result; } Handle result; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, result, - Runtime::DefineObjectProperty(js_object, name, obj_value, attr)); + Runtime::DefineObjectProperty(js_object, name, obj_value, attrs)); return *result; } @@ -1593,9 +1579,7 @@ RUNTIME_FUNCTION(Runtime_DefineGetterPropertyUnchecked) { CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); CONVERT_ARG_HANDLE_CHECKED(JSFunction, getter, 2); - CONVERT_SMI_ARG_CHECKED(unchecked, 3); - RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); - PropertyAttributes attrs = static_cast(unchecked); + CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); RETURN_FAILURE_ON_EXCEPTION( isolate, @@ -1611,9 +1595,7 @@ RUNTIME_FUNCTION(Runtime_DefineSetterPropertyUnchecked) { CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); CONVERT_ARG_HANDLE_CHECKED(JSFunction, setter, 2); - CONVERT_SMI_ARG_CHECKED(unchecked, 3); - RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); - PropertyAttributes attrs = static_cast(unchecked); + CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); RETURN_FAILURE_ON_EXCEPTION( isolate, diff --git a/src/runtime/runtime-utils.h b/src/runtime/runtime-utils.h index edddfca2d3..c44e40208f 100644 --- a/src/runtime/runtime-utils.h +++ b/src/runtime/runtime-utils.h @@ -87,6 +87,16 @@ namespace internal { RUNTIME_ASSERT(args[index]->ToInt32(&name)); +// Cast the given argument to PropertyAttributes and store its value in a +// variable with the given name. If the argument is not a Smi call or the +// enum value is out of range, call IllegalOperation and return. +#define CONVERT_PROPERTY_ATTRIBUTES_CHECKED(name, index) \ + RUNTIME_ASSERT(args[index]->IsSmi()); \ + RUNTIME_ASSERT( \ + (args.smi_at(index) & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); \ + PropertyAttributes name = static_cast(args.smi_at(index)); + + // A mechanism to return a pair of Object pointers in registers (if possible). // How this is achieved is calling convention-dependent. // All currently supported x86 compiles uses calling conventions that are cdecl