Commit e94f07aa authored by jkummerow's avatar jkummerow Committed by Commit bot

[cleanup] [proxies] Unify style of recently written code

In particular, return Maybe<bool> from any function that can throw, and
use MAYBE_RETURN and RETURN_FAILURE macros consistently where applicable.

No change in behavior intended.

Review URL: https://codereview.chromium.org/1513713002

Cr-Commit-Position: refs/heads/master@{#32723}
parent 897fecd5
...@@ -3526,11 +3526,11 @@ Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context, ...@@ -3526,11 +3526,11 @@ Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context,
desc.set_enumerable(!(attributes & v8::DontEnum)); desc.set_enumerable(!(attributes & v8::DontEnum));
desc.set_configurable(!(attributes & v8::DontDelete)); desc.set_configurable(!(attributes & v8::DontDelete));
desc.set_value(value_obj); desc.set_value(value_obj);
bool success = i::JSReceiver::DefineOwnProperty(isolate, self, key_obj, &desc, Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
i::Object::DONT_THROW); isolate, self, key_obj, &desc, i::Object::DONT_THROW);
// Even though we said DONT_THROW, there might be accessors that do throw. // Even though we said DONT_THROW, there might be accessors that do throw.
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return Just(success); return success;
} }
...@@ -3669,11 +3669,11 @@ MaybeLocal<Value> v8::Object::GetOwnPropertyDescriptor(Local<Context> context, ...@@ -3669,11 +3669,11 @@ MaybeLocal<Value> v8::Object::GetOwnPropertyDescriptor(Local<Context> context,
i::Handle<i::String> key_name = Utils::OpenHandle(*key); i::Handle<i::String> key_name = Utils::OpenHandle(*key);
i::PropertyDescriptor desc; i::PropertyDescriptor desc;
bool found = Maybe<bool> found =
i::JSReceiver::GetOwnPropertyDescriptor(isolate, obj, key_name, &desc); i::JSReceiver::GetOwnPropertyDescriptor(isolate, obj, key_name, &desc);
has_pending_exception = isolate->has_pending_exception(); has_pending_exception = found.IsNothing();
RETURN_ON_FAILED_EXECUTION(Value); RETURN_ON_FAILED_EXECUTION(Value);
if (!found) { if (!found.FromJust()) {
return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
} }
RETURN_ESCAPED(Utils::ToLocal(desc.ToObject(isolate))); RETURN_ESCAPED(Utils::ToLocal(desc.ToObject(isolate)));
......
...@@ -673,8 +673,9 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic( ...@@ -673,8 +673,9 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic(
// %ThrowTypeError% must not have a name property. // %ThrowTypeError% must not have a name property.
if (JSReceiver::DeleteProperty(function, factory()->name_string()) if (JSReceiver::DeleteProperty(function, factory()->name_string())
.IsNothing()) .IsNothing()) {
DCHECK(false); DCHECK(false);
}
// length needs to be non configurable. // length needs to be non configurable.
Handle<Object> value(Smi::FromInt(function->shared()->length()), isolate()); Handle<Object> value(Smi::FromInt(function->shared()->length()), isolate());
...@@ -683,8 +684,10 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic( ...@@ -683,8 +684,10 @@ Handle<JSFunction> Genesis::GetThrowTypeErrorIntrinsic(
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY)) static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY))
.Assert(); .Assert();
if (JSObject::PreventExtensions(function, Object::THROW_ON_ERROR).IsNothing()) if (JSObject::PreventExtensions(function, Object::THROW_ON_ERROR)
.IsNothing()) {
DCHECK(false); DCHECK(false);
}
return function; return function;
} }
......
...@@ -1458,12 +1458,11 @@ BUILTIN(ReflectDefineProperty) { ...@@ -1458,12 +1458,11 @@ BUILTIN(ReflectDefineProperty) {
return isolate->heap()->exception(); return isolate->heap()->exception();
} }
bool result = Maybe<bool> result =
JSReceiver::DefineOwnProperty(isolate, Handle<JSReceiver>::cast(target), JSReceiver::DefineOwnProperty(isolate, Handle<JSReceiver>::cast(target),
name, &desc, Object::DONT_THROW); name, &desc, Object::DONT_THROW);
if (isolate->has_pending_exception()) return isolate->heap()->exception(); MAYBE_RETURN(result, isolate->heap()->exception());
// TODO(neis): Make DefineOwnProperty return Maybe<bool>. return *isolate->factory()->ToBoolean(result.FromJust());
return *isolate->factory()->ToBoolean(result);
} }
...@@ -1539,10 +1538,10 @@ BUILTIN(ReflectGetOwnPropertyDescriptor) { ...@@ -1539,10 +1538,10 @@ BUILTIN(ReflectGetOwnPropertyDescriptor) {
Object::ToName(isolate, key)); Object::ToName(isolate, key));
PropertyDescriptor desc; PropertyDescriptor desc;
bool found = JSReceiver::GetOwnPropertyDescriptor( Maybe<bool> found = JSReceiver::GetOwnPropertyDescriptor(
isolate, Handle<JSReceiver>::cast(target), name, &desc); isolate, Handle<JSReceiver>::cast(target), name, &desc);
if (isolate->has_pending_exception()) return isolate->heap()->exception(); MAYBE_RETURN(found, isolate->heap()->exception());
if (!found) return isolate->heap()->undefined_value(); if (!found.FromJust()) return isolate->heap()->undefined_value();
return *desc.ToObject(isolate); return *desc.ToObject(isolate);
} }
......
...@@ -234,10 +234,10 @@ MaybeHandle<FixedArray> FilterProxyKeys(Isolate* isolate, Handle<JSProxy> owner, ...@@ -234,10 +234,10 @@ MaybeHandle<FixedArray> FilterProxyKeys(Isolate* isolate, Handle<JSProxy> owner,
if (key->FilterKey(filter)) continue; // Skip this key. if (key->FilterKey(filter)) continue; // Skip this key.
if (filter & ONLY_ENUMERABLE) { if (filter & ONLY_ENUMERABLE) {
PropertyDescriptor desc; PropertyDescriptor desc;
bool found = Maybe<bool> found =
JSProxy::GetOwnPropertyDescriptor(isolate, owner, key, &desc); JSProxy::GetOwnPropertyDescriptor(isolate, owner, key, &desc);
if (isolate->has_pending_exception()) return MaybeHandle<FixedArray>(); MAYBE_RETURN(found, MaybeHandle<FixedArray>());
if (!found || !desc.enumerable()) continue; // Skip this key. if (!found.FromJust() || !desc.enumerable()) continue; // Skip this key.
} }
// Keep this key. // Keep this key.
if (store_position != i) { if (store_position != i) {
...@@ -251,11 +251,12 @@ MaybeHandle<FixedArray> FilterProxyKeys(Isolate* isolate, Handle<JSProxy> owner, ...@@ -251,11 +251,12 @@ MaybeHandle<FixedArray> FilterProxyKeys(Isolate* isolate, Handle<JSProxy> owner,
} }
// Returns "false" in case of exception, "true" on success. // Returns "nothing" in case of exception, "true" on success.
bool KeyAccumulator::AddKeysFromProxy(Handle<JSProxy> proxy, Maybe<bool> KeyAccumulator::AddKeysFromProxy(Handle<JSProxy> proxy,
Handle<FixedArray> keys) { Handle<FixedArray> keys) {
ASSIGN_RETURN_ON_EXCEPTION_VALUE( ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, keys, FilterProxyKeys(isolate_, proxy, keys, filter_), false); isolate_, keys, FilterProxyKeys(isolate_, proxy, keys, filter_),
Nothing<bool>());
// Proxies define a complete list of keys with no distinction of // Proxies define a complete list of keys with no distinction of
// elements and properties, which breaks the normal assumption for the // elements and properties, which breaks the normal assumption for the
// KeyAccumulator. // KeyAccumulator.
...@@ -264,7 +265,7 @@ bool KeyAccumulator::AddKeysFromProxy(Handle<JSProxy> proxy, ...@@ -264,7 +265,7 @@ bool KeyAccumulator::AddKeysFromProxy(Handle<JSProxy> proxy,
// element keys for this level. Otherwise we would not fully respect the order // element keys for this level. Otherwise we would not fully respect the order
// given by the proxy. // given by the proxy.
level_string_length_ = -level_string_length_; level_string_length_ = -level_string_length_;
return true; return Just(true);
} }
......
...@@ -43,7 +43,7 @@ class KeyAccumulator final BASE_EMBEDDED { ...@@ -43,7 +43,7 @@ class KeyAccumulator final BASE_EMBEDDED {
void AddKeys(Handle<JSObject> array, void AddKeys(Handle<JSObject> array,
AddKeyConversion convert = DO_NOT_CONVERT); AddKeyConversion convert = DO_NOT_CONVERT);
void AddKeysFromProxy(Handle<JSObject> array); void AddKeysFromProxy(Handle<JSObject> array);
bool AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys); Maybe<bool> AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys);
void AddElementKeysFromInterceptor(Handle<JSObject> array); void AddElementKeysFromInterceptor(Handle<JSObject> array);
// Jump to the next level, pushing the current |levelLength_| to // Jump to the next level, pushing the current |levelLength_| to
// |levelLengths_| and adding a new list to |elements_|. // |levelLengths_| and adding a new list to |elements_|.
......
This diff is collapsed.
...@@ -1830,42 +1830,37 @@ class JSReceiver: public HeapObject { ...@@ -1830,42 +1830,37 @@ class JSReceiver: public HeapObject {
Handle<Object> properties); Handle<Object> properties);
// "virtual" dispatcher to the correct [[DefineOwnProperty]] implementation. // "virtual" dispatcher to the correct [[DefineOwnProperty]] implementation.
static bool DefineOwnProperty(Isolate* isolate, Handle<JSReceiver> object, MUST_USE_RESULT static Maybe<bool> DefineOwnProperty(
Handle<Object> key, PropertyDescriptor* desc, Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key,
ShouldThrow should_throw); PropertyDescriptor* desc, ShouldThrow should_throw);
// ES6 7.3.4 (when passed DONT_THROW) // ES6 7.3.4 (when passed DONT_THROW)
MUST_USE_RESULT static Maybe<bool> CreateDataProperty( MUST_USE_RESULT static Maybe<bool> CreateDataProperty(
LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
// ES6 9.1.6.1 // ES6 9.1.6.1
static bool OrdinaryDefineOwnProperty(Isolate* isolate, MUST_USE_RESULT static Maybe<bool> OrdinaryDefineOwnProperty(
Handle<JSObject> object, Isolate* isolate, Handle<JSObject> object, Handle<Object> key,
Handle<Object> key, PropertyDescriptor* desc, ShouldThrow should_throw);
PropertyDescriptor* desc, MUST_USE_RESULT static Maybe<bool> OrdinaryDefineOwnProperty(
ShouldThrow should_throw); LookupIterator* it, PropertyDescriptor* desc, ShouldThrow should_throw);
static bool OrdinaryDefineOwnProperty(LookupIterator* it,
PropertyDescriptor* desc,
ShouldThrow should_throw);
// ES6 9.1.6.2 // ES6 9.1.6.2
static bool IsCompatiblePropertyDescriptor(Isolate* isolate, bool extensible, MUST_USE_RESULT static Maybe<bool> IsCompatiblePropertyDescriptor(
PropertyDescriptor* desc, Isolate* isolate, bool extensible, PropertyDescriptor* desc,
PropertyDescriptor* current, PropertyDescriptor* current, Handle<Name> property_name);
Handle<Name> property_name);
// ES6 9.1.6.3 // ES6 9.1.6.3
// |it| can be NULL in cases where the ES spec passes |undefined| as the // |it| can be NULL in cases where the ES spec passes |undefined| as the
// receiver. Exactly one of |it| and |property_name| must be provided. // receiver. Exactly one of |it| and |property_name| must be provided.
static bool ValidateAndApplyPropertyDescriptor( MUST_USE_RESULT static Maybe<bool> ValidateAndApplyPropertyDescriptor(
Isolate* isolate, LookupIterator* it, bool extensible, Isolate* isolate, LookupIterator* it, bool extensible,
PropertyDescriptor* desc, PropertyDescriptor* current, PropertyDescriptor* desc, PropertyDescriptor* current,
ShouldThrow should_throw, Handle<Name> property_name = Handle<Name>()); ShouldThrow should_throw, Handle<Name> property_name = Handle<Name>());
static bool GetOwnPropertyDescriptor(Isolate* isolate, MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor(
Handle<JSReceiver> object, Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key,
Handle<Object> key, PropertyDescriptor* desc);
PropertyDescriptor* desc); MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor(
static bool GetOwnPropertyDescriptor(LookupIterator* it, LookupIterator* it, PropertyDescriptor* desc);
PropertyDescriptor* desc);
typedef PropertyAttributes IntegrityLevel; typedef PropertyAttributes IntegrityLevel;
...@@ -9519,14 +9514,14 @@ class JSProxy: public JSReceiver { ...@@ -9519,14 +9514,14 @@ class JSProxy: public JSReceiver {
Handle<JSProxy> proxy, ShouldThrow should_throw); Handle<JSProxy> proxy, ShouldThrow should_throw);
// ES6 9.5.5 // ES6 9.5.5
static bool GetOwnPropertyDescriptor(Isolate* isolate, Handle<JSProxy> proxy, MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor(
Handle<Name> name, Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name,
PropertyDescriptor* desc); PropertyDescriptor* desc);
// ES6 9.5.6 // ES6 9.5.6
static bool DefineOwnProperty(Isolate* isolate, Handle<JSProxy> object, MUST_USE_RESULT static Maybe<bool> DefineOwnProperty(
Handle<Object> key, PropertyDescriptor* desc, Isolate* isolate, Handle<JSProxy> object, Handle<Object> key,
ShouldThrow should_throw); PropertyDescriptor* desc, ShouldThrow should_throw);
// ES6 9.5.7 // ES6 9.5.7
MUST_USE_RESULT static Maybe<bool> HasProperty(Isolate* isolate, MUST_USE_RESULT static Maybe<bool> HasProperty(Isolate* isolate,
...@@ -9550,13 +9545,15 @@ class JSProxy: public JSReceiver { ...@@ -9550,13 +9545,15 @@ class JSProxy: public JSReceiver {
Handle<JSProxy> proxy, Handle<Name> name, LanguageMode language_mode); Handle<JSProxy> proxy, Handle<Name> name, LanguageMode language_mode);
// ES6 9.5.11 // ES6 9.5.11
static bool Enumerate(Isolate* isolate, Handle<JSReceiver> receiver, MUST_USE_RESULT static Maybe<bool> Enumerate(Isolate* isolate,
Handle<JSProxy> proxy, KeyAccumulator* accumulator); Handle<JSReceiver> receiver,
Handle<JSProxy> proxy,
KeyAccumulator* accumulator);
// ES6 9.5.12 // ES6 9.5.12
static bool OwnPropertyKeys(Isolate* isolate, Handle<JSReceiver> receiver, MUST_USE_RESULT static Maybe<bool> OwnPropertyKeys(
Handle<JSProxy> proxy, PropertyFilter filter, Isolate* isolate, Handle<JSReceiver> receiver, Handle<JSProxy> proxy,
KeyAccumulator* accumulator); PropertyFilter filter, KeyAccumulator* accumulator);
MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes(
LookupIterator* it); LookupIterator* it);
...@@ -9580,11 +9577,6 @@ class JSProxy: public JSReceiver { ...@@ -9580,11 +9577,6 @@ class JSProxy: public JSReceiver {
static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy); static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy);
private: private:
friend class JSReceiver;
MUST_USE_RESULT static MaybeHandle<Object> GetTrap(Handle<JSProxy> proxy,
Handle<String> trap);
DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
}; };
...@@ -10063,16 +10055,18 @@ class JSArray: public JSObject { ...@@ -10063,16 +10055,18 @@ class JSArray: public JSObject {
static inline void SetContent(Handle<JSArray> array, static inline void SetContent(Handle<JSArray> array,
Handle<FixedArrayBase> storage); Handle<FixedArrayBase> storage);
static bool DefineOwnProperty(Isolate* isolate, Handle<JSArray> o, // ES6 9.4.2.1
Handle<Object> name, PropertyDescriptor* desc, MUST_USE_RESULT static Maybe<bool> DefineOwnProperty(
ShouldThrow should_throw); Isolate* isolate, Handle<JSArray> o, Handle<Object> name,
PropertyDescriptor* desc, ShouldThrow should_throw);
static bool AnythingToArrayLength(Isolate* isolate, static bool AnythingToArrayLength(Isolate* isolate,
Handle<Object> length_object, Handle<Object> length_object,
uint32_t* output); uint32_t* output);
static bool ArraySetLength(Isolate* isolate, Handle<JSArray> a, MUST_USE_RESULT static Maybe<bool> ArraySetLength(Isolate* isolate,
PropertyDescriptor* desc, Handle<JSArray> a,
ShouldThrow should_throw); PropertyDescriptor* desc,
ShouldThrow should_throw);
DECLARE_CAST(JSArray) DECLARE_CAST(JSArray)
......
...@@ -287,11 +287,11 @@ RUNTIME_FUNCTION(Runtime_GetOwnProperty) { ...@@ -287,11 +287,11 @@ RUNTIME_FUNCTION(Runtime_GetOwnProperty) {
// 3. Let desc be ? obj.[[GetOwnProperty]](key). // 3. Let desc be ? obj.[[GetOwnProperty]](key).
PropertyDescriptor desc; PropertyDescriptor desc;
bool found = JSReceiver::GetOwnPropertyDescriptor( Maybe<bool> found = JSReceiver::GetOwnPropertyDescriptor(
isolate, Handle<JSReceiver>::cast(object), key, &desc); isolate, Handle<JSReceiver>::cast(object), key, &desc);
if (isolate->has_pending_exception()) return isolate->heap()->exception(); MAYBE_RETURN(found, isolate->heap()->exception());
// 4. Return FromPropertyDescriptor(desc). // 4. Return FromPropertyDescriptor(desc).
if (!found) return isolate->heap()->undefined_value(); if (!found.FromJust()) return isolate->heap()->undefined_value();
return *desc.ToObject(isolate); return *desc.ToObject(isolate);
} }
......
...@@ -826,8 +826,10 @@ RUNTIME_FUNCTION(Runtime_DeclareModules) { ...@@ -826,8 +826,10 @@ RUNTIME_FUNCTION(Runtime_DeclareModules) {
} }
} }
if (JSObject::PreventExtensions(module, Object::THROW_ON_ERROR).IsNothing()) if (JSObject::PreventExtensions(module, Object::THROW_ON_ERROR)
.IsNothing()) {
DCHECK(false); DCHECK(false);
}
} }
DCHECK(!isolate->has_pending_exception()); DCHECK(!isolate->has_pending_exception());
......
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