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