Add Object::IsNullOrUndefined(Isolate*) helper method
The pattern IsNull(isolate) || IsUndefined(isolate) is used in many places all over the code base. Review-Url: https://codereview.chromium.org/2601503002 Cr-Commit-Position: refs/heads/master@{#42138}
This commit is contained in:
parent
e24f3f3bd5
commit
09167bf6cd
29
include/v8.h
29
include/v8.h
@ -1921,9 +1921,16 @@ class V8_EXPORT Value : public Data {
|
||||
*/
|
||||
V8_INLINE bool IsNull() const;
|
||||
|
||||
/**
|
||||
* Returns true if this value is true.
|
||||
/**
|
||||
* Returns true if this value is either the null or the undefined value.
|
||||
* See ECMA-262
|
||||
* 4.3.11. and 4.3.12
|
||||
*/
|
||||
V8_INLINE bool IsNullOrUndefined() const;
|
||||
|
||||
/**
|
||||
* Returns true if this value is true.
|
||||
*/
|
||||
bool IsTrue() const;
|
||||
|
||||
/**
|
||||
@ -2243,6 +2250,7 @@ class V8_EXPORT Value : public Data {
|
||||
private:
|
||||
V8_INLINE bool QuickIsUndefined() const;
|
||||
V8_INLINE bool QuickIsNull() const;
|
||||
V8_INLINE bool QuickIsNullOrUndefined() const;
|
||||
V8_INLINE bool QuickIsString() const;
|
||||
bool FullIsUndefined() const;
|
||||
bool FullIsNull() const;
|
||||
@ -9144,6 +9152,23 @@ bool Value::QuickIsNull() const {
|
||||
return (I::GetOddballKind(obj) == I::kNullOddballKind);
|
||||
}
|
||||
|
||||
bool Value::IsNullOrUndefined() const {
|
||||
#ifdef V8_ENABLE_CHECKS
|
||||
return FullIsNull() || FullIsUndefined();
|
||||
#else
|
||||
return QuickIsNullOrUndefined();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Value::QuickIsNullOrUndefined() const {
|
||||
typedef internal::Object O;
|
||||
typedef internal::Internals I;
|
||||
O* obj = *reinterpret_cast<O* const*>(this);
|
||||
if (!I::HasHeapObjectTag(obj)) return false;
|
||||
if (I::GetInstanceType(obj) != I::kOddballType) return false;
|
||||
int kind = I::GetOddballKind(obj);
|
||||
return kind == I::kNullOddballKind || kind == I::kUndefinedOddballKind;
|
||||
}
|
||||
|
||||
bool Value::IsString() const {
|
||||
#ifdef V8_ENABLE_CHECKS
|
||||
|
@ -335,14 +335,15 @@ Handle<JSGlobalProxy> Bootstrapper::NewRemoteContext(
|
||||
}
|
||||
|
||||
void Bootstrapper::DetachGlobal(Handle<Context> env) {
|
||||
env->GetIsolate()->counters()->errors_thrown_per_context()->AddSample(
|
||||
env->GetErrorsThrown());
|
||||
Isolate* isolate = env->GetIsolate();
|
||||
isolate->counters()->errors_thrown_per_context()->AddSample(
|
||||
env->GetErrorsThrown());
|
||||
|
||||
Factory* factory = env->GetIsolate()->factory();
|
||||
Heap* heap = isolate->heap();
|
||||
Handle<JSGlobalProxy> global_proxy(JSGlobalProxy::cast(env->global_proxy()));
|
||||
global_proxy->set_native_context(*factory->null_value());
|
||||
JSObject::ForceSetPrototype(global_proxy, factory->null_value());
|
||||
global_proxy->map()->SetConstructor(*factory->null_value());
|
||||
global_proxy->set_native_context(heap->null_value());
|
||||
JSObject::ForceSetPrototype(global_proxy, isolate->factory()->null_value());
|
||||
global_proxy->map()->SetConstructor(heap->null_value());
|
||||
if (FLAG_track_detached_contexts) {
|
||||
env->GetIsolate()->AddDetachedContext(env);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ inline bool ClampedToInteger(Isolate* isolate, Object* object, int* out) {
|
||||
*out = static_cast<int>(value);
|
||||
}
|
||||
return true;
|
||||
} else if (object->IsUndefined(isolate) || object->IsNull(isolate)) {
|
||||
} else if (object->IsNullOrUndefined(isolate)) {
|
||||
*out = 0;
|
||||
return true;
|
||||
} else if (object->IsBoolean()) {
|
||||
@ -1343,7 +1343,7 @@ BUILTIN(ArrayConcat) {
|
||||
|
||||
Handle<Object> receiver = args.receiver();
|
||||
// TODO(bmeurer): Do we really care about the exact exception message here?
|
||||
if (receiver->IsNull(isolate) || receiver->IsUndefined(isolate)) {
|
||||
if (receiver->IsNullOrUndefined(isolate)) {
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined,
|
||||
isolate->factory()->NewStringFromAsciiChecked(
|
||||
|
@ -636,7 +636,7 @@ BUILTIN(ObjectSetPrototypeOf) {
|
||||
|
||||
// 1. Let O be ? RequireObjectCoercible(O).
|
||||
Handle<Object> object = args.atOrUndefined(isolate, 1);
|
||||
if (object->IsNull(isolate) || object->IsUndefined(isolate)) {
|
||||
if (object->IsNullOrUndefined(isolate)) {
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined,
|
||||
isolate->factory()->NewStringFromAsciiChecked(
|
||||
@ -682,7 +682,7 @@ BUILTIN(ObjectPrototypeSetProto) {
|
||||
HandleScope scope(isolate);
|
||||
// 1. Let O be ? RequireObjectCoercible(this value).
|
||||
Handle<Object> object = args.receiver();
|
||||
if (object->IsNull(isolate) || object->IsUndefined(isolate)) {
|
||||
if (object->IsNullOrUndefined(isolate)) {
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined,
|
||||
isolate->factory()->NewStringFromAsciiChecked(
|
||||
|
@ -145,8 +145,7 @@ class BuiltinArguments : public Arguments {
|
||||
// or converts the receiver to a String otherwise and assigns it to a new var
|
||||
// with the given {name}.
|
||||
#define TO_THIS_STRING(name, method) \
|
||||
if (args.receiver()->IsNull(isolate) || \
|
||||
args.receiver()->IsUndefined(isolate)) { \
|
||||
if (args.receiver()->IsNullOrUndefined(isolate)) { \
|
||||
THROW_NEW_ERROR_RETURN_FAILURE( \
|
||||
isolate, \
|
||||
NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, \
|
||||
|
@ -456,7 +456,7 @@ Reduction JSCallReducer::ReduceJSCallFunction(Node* node) {
|
||||
isolate());
|
||||
CallFunctionParameters const& p = CallFunctionParametersOf(node->op());
|
||||
ConvertReceiverMode const convert_mode =
|
||||
(bound_this->IsNull(isolate()) || bound_this->IsUndefined(isolate()))
|
||||
(bound_this->IsNullOrUndefined(isolate()))
|
||||
? ConvertReceiverMode::kNullOrUndefined
|
||||
: ConvertReceiverMode::kNotNullOrUndefined;
|
||||
size_t arity = p.arity();
|
||||
|
@ -2045,7 +2045,7 @@ void Debug::SetEventListener(Handle<Object> callback,
|
||||
event_listener_data_ = Handle<Object>();
|
||||
|
||||
// Set new entry.
|
||||
if (!callback->IsUndefined(isolate_) && !callback->IsNull(isolate_)) {
|
||||
if (!callback->IsNullOrUndefined(isolate_)) {
|
||||
event_listener_ = global_handles->Create(*callback);
|
||||
if (data.is_null()) data = isolate_->factory()->undefined_value();
|
||||
event_listener_data_ = global_handles->Create(*data);
|
||||
|
@ -529,10 +529,8 @@ void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
|
||||
true,
|
||||
true_label_,
|
||||
false_label_);
|
||||
DCHECK(lit->IsNull(isolate()) || lit->IsUndefined(isolate()) ||
|
||||
!lit->IsUndetectable());
|
||||
if (lit->IsUndefined(isolate()) || lit->IsNull(isolate()) ||
|
||||
lit->IsFalse(isolate())) {
|
||||
DCHECK(lit->IsNullOrUndefined(isolate()) || !lit->IsUndetectable());
|
||||
if (lit->IsNullOrUndefined(isolate()) || lit->IsFalse(isolate())) {
|
||||
if (false_label_ != fall_through_) __ b(false_label_);
|
||||
} else if (lit->IsTrue(isolate()) || lit->IsJSObject()) {
|
||||
if (true_label_ != fall_through_) __ b(true_label_);
|
||||
|
@ -519,10 +519,8 @@ void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
|
||||
true,
|
||||
true_label_,
|
||||
false_label_);
|
||||
DCHECK(lit->IsNull(isolate()) || lit->IsUndefined(isolate()) ||
|
||||
!lit->IsUndetectable());
|
||||
if (lit->IsUndefined(isolate()) || lit->IsNull(isolate()) ||
|
||||
lit->IsFalse(isolate())) {
|
||||
DCHECK(lit->IsNullOrUndefined(isolate()) || !lit->IsUndetectable());
|
||||
if (lit->IsNullOrUndefined(isolate()) || lit->IsFalse(isolate())) {
|
||||
if (false_label_ != fall_through_) __ B(false_label_);
|
||||
} else if (lit->IsTrue(isolate()) || lit->IsJSObject()) {
|
||||
if (true_label_ != fall_through_) __ B(true_label_);
|
||||
|
@ -480,10 +480,8 @@ void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
|
||||
true,
|
||||
true_label_,
|
||||
false_label_);
|
||||
DCHECK(lit->IsNull(isolate()) || lit->IsUndefined(isolate()) ||
|
||||
!lit->IsUndetectable());
|
||||
if (lit->IsUndefined(isolate()) || lit->IsNull(isolate()) ||
|
||||
lit->IsFalse(isolate())) {
|
||||
DCHECK(lit->IsNullOrUndefined(isolate()) || !lit->IsUndetectable());
|
||||
if (lit->IsNullOrUndefined(isolate()) || lit->IsFalse(isolate())) {
|
||||
if (false_label_ != fall_through_) __ jmp(false_label_);
|
||||
} else if (lit->IsTrue(isolate()) || lit->IsJSObject()) {
|
||||
if (true_label_ != fall_through_) __ jmp(true_label_);
|
||||
|
@ -522,10 +522,8 @@ void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
|
||||
true,
|
||||
true_label_,
|
||||
false_label_);
|
||||
DCHECK(lit->IsNull(isolate()) || lit->IsUndefined(isolate()) ||
|
||||
!lit->IsUndetectable());
|
||||
if (lit->IsUndefined(isolate()) || lit->IsNull(isolate()) ||
|
||||
lit->IsFalse(isolate())) {
|
||||
DCHECK(lit->IsNullOrUndefined(isolate()) || !lit->IsUndetectable());
|
||||
if (lit->IsNullOrUndefined(isolate()) || lit->IsFalse(isolate())) {
|
||||
if (false_label_ != fall_through_) __ Branch(false_label_);
|
||||
} else if (lit->IsTrue(isolate()) || lit->IsJSObject()) {
|
||||
if (true_label_ != fall_through_) __ Branch(true_label_);
|
||||
|
@ -522,10 +522,8 @@ void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
|
||||
true,
|
||||
true_label_,
|
||||
false_label_);
|
||||
DCHECK(lit->IsNull(isolate()) || lit->IsUndefined(isolate()) ||
|
||||
!lit->IsUndetectable());
|
||||
if (lit->IsUndefined(isolate()) || lit->IsNull(isolate()) ||
|
||||
lit->IsFalse(isolate())) {
|
||||
DCHECK(lit->IsNullOrUndefined(isolate()) || !lit->IsUndetectable());
|
||||
if (lit->IsNullOrUndefined(isolate()) || lit->IsFalse(isolate())) {
|
||||
if (false_label_ != fall_through_) __ Branch(false_label_);
|
||||
} else if (lit->IsTrue(isolate()) || lit->IsJSObject()) {
|
||||
if (true_label_ != fall_through_) __ Branch(true_label_);
|
||||
|
@ -511,10 +511,8 @@ void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const {
|
||||
void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
|
||||
codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_,
|
||||
false_label_);
|
||||
DCHECK(lit->IsNull(isolate()) || lit->IsUndefined(isolate()) ||
|
||||
!lit->IsUndetectable());
|
||||
if (lit->IsUndefined(isolate()) || lit->IsNull(isolate()) ||
|
||||
lit->IsFalse(isolate())) {
|
||||
DCHECK(lit->IsNullOrUndefined(isolate()) || !lit->IsUndetectable());
|
||||
if (lit->IsNullOrUndefined(isolate()) || lit->IsFalse(isolate())) {
|
||||
if (false_label_ != fall_through_) __ b(false_label_);
|
||||
} else if (lit->IsTrue(isolate()) || lit->IsJSObject()) {
|
||||
if (true_label_ != fall_through_) __ b(true_label_);
|
||||
|
@ -502,10 +502,8 @@ void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const {
|
||||
void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
|
||||
codegen()->PrepareForBailoutBeforeSplit(condition(), true, true_label_,
|
||||
false_label_);
|
||||
DCHECK(lit->IsNull(isolate()) || lit->IsUndefined(isolate()) ||
|
||||
!lit->IsUndetectable());
|
||||
if (lit->IsUndefined(isolate()) || lit->IsNull(isolate()) ||
|
||||
lit->IsFalse(isolate())) {
|
||||
DCHECK(lit->IsNullOrUndefined(isolate()) || !lit->IsUndetectable());
|
||||
if (lit->IsNullOrUndefined(isolate()) || lit->IsFalse(isolate())) {
|
||||
if (false_label_ != fall_through_) __ b(false_label_);
|
||||
} else if (lit->IsTrue(isolate()) || lit->IsJSObject()) {
|
||||
if (true_label_ != fall_through_) __ b(true_label_);
|
||||
@ -2712,7 +2710,6 @@ BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState(
|
||||
isolate->builtins()->OnStackReplacement()->entry());
|
||||
return ON_STACK_REPLACEMENT;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
#endif // V8_TARGET_ARCH_S390
|
||||
|
@ -496,10 +496,8 @@ void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
|
||||
true,
|
||||
true_label_,
|
||||
false_label_);
|
||||
DCHECK(lit->IsNull(isolate()) || lit->IsUndefined(isolate()) ||
|
||||
!lit->IsUndetectable());
|
||||
if (lit->IsUndefined(isolate()) || lit->IsNull(isolate()) ||
|
||||
lit->IsFalse(isolate())) {
|
||||
DCHECK(lit->IsNullOrUndefined(isolate()) || !lit->IsUndetectable());
|
||||
if (lit->IsNullOrUndefined(isolate()) || lit->IsFalse(isolate())) {
|
||||
if (false_label_ != fall_through_) __ jmp(false_label_);
|
||||
} else if (lit->IsTrue(isolate()) || lit->IsJSObject()) {
|
||||
if (true_label_ != fall_through_) __ jmp(true_label_);
|
||||
|
@ -477,10 +477,8 @@ void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const {
|
||||
true,
|
||||
true_label_,
|
||||
false_label_);
|
||||
DCHECK(lit->IsNull(isolate()) || lit->IsUndefined(isolate()) ||
|
||||
!lit->IsUndetectable());
|
||||
if (lit->IsUndefined(isolate()) || lit->IsNull(isolate()) ||
|
||||
lit->IsFalse(isolate())) {
|
||||
DCHECK(lit->IsNullOrUndefined(isolate()) || !lit->IsUndetectable());
|
||||
if (lit->IsNullOrUndefined(isolate()) || lit->IsFalse(isolate())) {
|
||||
if (false_label_ != fall_through_) __ jmp(false_label_);
|
||||
} else if (lit->IsTrue(isolate()) || lit->IsJSObject()) {
|
||||
if (true_label_ != fall_through_) __ jmp(true_label_);
|
||||
|
@ -161,7 +161,7 @@ void PropertyHandlerCompiler::NonexistentFrontendHeader(Handle<Name> name,
|
||||
last_map = map();
|
||||
// If |type| has null as its prototype, |holder()| is
|
||||
// Handle<JSObject>::null().
|
||||
DCHECK(last_map->prototype() == isolate()->heap()->null_value());
|
||||
DCHECK(last_map->prototype()->IsNull(isolate()));
|
||||
} else {
|
||||
last_map = handle(holder()->map());
|
||||
// This condition matches the branches below.
|
||||
|
@ -387,7 +387,7 @@ void IC::UpdateState(Handle<Object> receiver, Handle<Object> name) {
|
||||
update_receiver_map(receiver);
|
||||
if (!name->IsString()) return;
|
||||
if (state() != MONOMORPHIC && state() != POLYMORPHIC) return;
|
||||
if (receiver->IsUndefined(isolate()) || receiver->IsNull(isolate())) return;
|
||||
if (receiver->IsNullOrUndefined(isolate())) return;
|
||||
|
||||
// Remove the target from the code cache if it became invalid
|
||||
// because of changes in the prototype chain to avoid hitting it
|
||||
@ -664,7 +664,7 @@ void IC::ConfigureVectorState(MapHandleList* maps,
|
||||
MaybeHandle<Object> LoadIC::Load(Handle<Object> object, Handle<Name> name) {
|
||||
// If the object is undefined or null it's illegal to try to get any
|
||||
// of its properties; throw a TypeError in that case.
|
||||
if (object->IsUndefined(isolate()) || object->IsNull(isolate())) {
|
||||
if (object->IsNullOrUndefined(isolate())) {
|
||||
if (FLAG_use_ic && state() != UNINITIALIZED && state() != PREMONOMORPHIC) {
|
||||
// Ensure the IC state progresses.
|
||||
TRACE_HANDLER_STATS(isolate(), LoadIC_NonReceiver);
|
||||
@ -1818,7 +1818,7 @@ MaybeHandle<Object> StoreIC::Store(Handle<Object> object, Handle<Name> name,
|
||||
|
||||
// If the object is undefined or null it's illegal to try to set any
|
||||
// properties on it; throw a TypeError in that case.
|
||||
if (object->IsUndefined(isolate()) || object->IsNull(isolate())) {
|
||||
if (object->IsNullOrUndefined(isolate())) {
|
||||
if (FLAG_use_ic && state() != UNINITIALIZED && state() != PREMONOMORPHIC) {
|
||||
// Ensure the IC state progresses.
|
||||
TRACE_HANDLER_STATS(isolate(), StoreIC_NonReceiver);
|
||||
|
@ -50,8 +50,7 @@ v8::Local<v8::String> toV8String(v8::Isolate* isolate,
|
||||
}
|
||||
|
||||
String16 toProtocolString(v8::Local<v8::String> value) {
|
||||
if (value.IsEmpty() || value->IsNull() || value->IsUndefined())
|
||||
return String16();
|
||||
if (value.IsEmpty() || value->IsNullOrUndefined()) return String16();
|
||||
std::unique_ptr<UChar[]> buffer(new UChar[value->Length()]);
|
||||
value->Write(reinterpret_cast<uint16_t*>(buffer.get()), 0, value->Length());
|
||||
return String16(buffer.get(), value->Length());
|
||||
|
@ -371,7 +371,7 @@ Handle<Object> JSStackFrame::GetScriptNameOrSourceUrl() {
|
||||
}
|
||||
|
||||
Handle<Object> JSStackFrame::GetMethodName() {
|
||||
if (receiver_->IsNull(isolate_) || receiver_->IsUndefined(isolate_)) {
|
||||
if (receiver_->IsNullOrUndefined(isolate_)) {
|
||||
return isolate_->factory()->null_value();
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ Handle<Object> JSStackFrame::GetTypeName() {
|
||||
// TODO(jgruber): Check for strict/constructor here as in
|
||||
// CallSitePrototypeGetThis.
|
||||
|
||||
if (receiver_->IsNull(isolate_) || receiver_->IsUndefined(isolate_))
|
||||
if (receiver_->IsNullOrUndefined(isolate_))
|
||||
return isolate_->factory()->null_value();
|
||||
|
||||
if (receiver_->IsJSProxy()) return isolate_->factory()->Proxy_string();
|
||||
@ -457,8 +457,7 @@ bool JSStackFrame::IsNative() {
|
||||
}
|
||||
|
||||
bool JSStackFrame::IsToplevel() {
|
||||
return receiver_->IsJSGlobalProxy() || receiver_->IsNull(isolate_) ||
|
||||
receiver_->IsUndefined(isolate_);
|
||||
return receiver_->IsJSGlobalProxy() || receiver_->IsNullOrUndefined(isolate_);
|
||||
}
|
||||
|
||||
bool JSStackFrame::IsConstructor() {
|
||||
|
@ -218,6 +218,16 @@ HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DEF)
|
||||
ODDBALL_LIST(IS_TYPE_FUNCTION_DEF)
|
||||
#undef IS_TYPE_FUNCTION_DEF
|
||||
|
||||
bool Object::IsNullOrUndefined(Isolate* isolate) const {
|
||||
Heap* heap = isolate->heap();
|
||||
return this == heap->null_value() || this == heap->undefined_value();
|
||||
}
|
||||
|
||||
bool HeapObject::IsNullOrUndefined(Isolate* isolate) const {
|
||||
Heap* heap = isolate->heap();
|
||||
return this == heap->null_value() || this == heap->undefined_value();
|
||||
}
|
||||
|
||||
bool HeapObject::IsString() const {
|
||||
return map()->instance_type() < FIRST_NONSTRING_TYPE;
|
||||
}
|
||||
|
@ -444,7 +444,7 @@ bool Object::BooleanValue() {
|
||||
DCHECK(IsHeapObject());
|
||||
Isolate* isolate = HeapObject::cast(this)->GetIsolate();
|
||||
if (IsBoolean()) return IsTrue(isolate);
|
||||
if (IsUndefined(isolate) || IsNull(isolate)) return false;
|
||||
if (IsNullOrUndefined(isolate)) return false;
|
||||
if (IsUndetectable()) return false; // Undetectable object is false.
|
||||
if (IsString()) return String::cast(this)->length() != 0;
|
||||
if (IsHeapNumber()) return HeapNumber::cast(this)->HeapNumberBooleanValue();
|
||||
@ -887,7 +887,7 @@ MaybeHandle<Object> Object::GetMethod(Handle<JSReceiver> receiver,
|
||||
Isolate* isolate = receiver->GetIsolate();
|
||||
ASSIGN_RETURN_ON_EXCEPTION(isolate, func,
|
||||
JSReceiver::GetProperty(receiver, name), Object);
|
||||
if (func->IsNull(isolate) || func->IsUndefined(isolate)) {
|
||||
if (func->IsNullOrUndefined(isolate)) {
|
||||
return isolate->factory()->undefined_value();
|
||||
}
|
||||
if (!func->IsCallable()) {
|
||||
@ -11890,7 +11890,7 @@ ComparisonResult String::Compare(Handle<String> x, Handle<String> y) {
|
||||
|
||||
Object* String::IndexOf(Isolate* isolate, Handle<Object> receiver,
|
||||
Handle<Object> search, Handle<Object> position) {
|
||||
if (receiver->IsNull(isolate) || receiver->IsUndefined(isolate)) {
|
||||
if (receiver->IsNullOrUndefined(isolate)) {
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined,
|
||||
isolate->factory()->NewStringFromAsciiChecked(
|
||||
@ -12091,7 +12091,7 @@ int StringMatchBackwards(Vector<const schar> subject,
|
||||
|
||||
Object* String::LastIndexOf(Isolate* isolate, Handle<Object> receiver,
|
||||
Handle<Object> search, Handle<Object> position) {
|
||||
if (receiver->IsNull(isolate) || receiver->IsUndefined(isolate)) {
|
||||
if (receiver->IsNullOrUndefined(isolate)) {
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined,
|
||||
isolate->factory()->NewStringFromAsciiChecked(
|
||||
|
@ -1162,11 +1162,14 @@ class Object {
|
||||
OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
|
||||
HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
|
||||
#undef IS_TYPE_FUNCTION_DECL
|
||||
|
||||
#define IS_TYPE_FUNCTION_DECL(Type, Value) \
|
||||
INLINE(bool Is##Type(Isolate* isolate) const);
|
||||
ODDBALL_LIST(IS_TYPE_FUNCTION_DECL)
|
||||
#undef IS_TYPE_FUNCTION_DECL
|
||||
|
||||
INLINE(bool IsNullOrUndefined(Isolate* isolate) const);
|
||||
|
||||
// A non-keyed store is of the form a.x = foo or a["x"] = foo whereas
|
||||
// a keyed store is of the form a[expression] = foo.
|
||||
enum StoreFromKeyed {
|
||||
@ -1711,6 +1714,8 @@ class HeapObject: public Object {
|
||||
ODDBALL_LIST(IS_TYPE_FUNCTION_DECL)
|
||||
#undef IS_TYPE_FUNCTION_DECL
|
||||
|
||||
INLINE(bool IsNullOrUndefined(Isolate* isolate) const);
|
||||
|
||||
#define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \
|
||||
INLINE(bool Is##Name() const);
|
||||
STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
|
||||
|
@ -538,7 +538,7 @@ RUNTIME_FUNCTION(Runtime_ArrayIndexOf) {
|
||||
|
||||
// Let O be ? ToObject(this value).
|
||||
Handle<Object> receiver_obj = args.at(0);
|
||||
if (receiver_obj->IsNull(isolate) || receiver_obj->IsUndefined(isolate)) {
|
||||
if (receiver_obj->IsNullOrUndefined(isolate)) {
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined,
|
||||
isolate->factory()->NewStringFromAsciiChecked(
|
||||
|
@ -80,8 +80,7 @@ RUNTIME_FUNCTION(Runtime_HandleDebuggerStatement) {
|
||||
RUNTIME_FUNCTION(Runtime_SetDebugEventListener) {
|
||||
SealHandleScope shs(isolate);
|
||||
DCHECK_EQ(2, args.length());
|
||||
CHECK(args[0]->IsJSFunction() || args[0]->IsUndefined(isolate) ||
|
||||
args[0]->IsNull(isolate));
|
||||
CHECK(args[0]->IsJSFunction() || args[0]->IsNullOrUndefined(isolate));
|
||||
CONVERT_ARG_HANDLE_CHECKED(Object, callback, 0);
|
||||
CONVERT_ARG_HANDLE_CHECKED(Object, data, 1);
|
||||
isolate->debug()->SetEventListener(callback, data);
|
||||
@ -1702,13 +1701,13 @@ Handle<Object> ScriptLocationFromLine(Isolate* isolate, Handle<Script> script,
|
||||
// additionally subtracting corresponding offsets.
|
||||
|
||||
int32_t line = 0;
|
||||
if (!opt_line->IsNull(isolate) && !opt_line->IsUndefined(isolate)) {
|
||||
if (!opt_line->IsNullOrUndefined(isolate)) {
|
||||
CHECK(opt_line->IsNumber());
|
||||
line = NumberToInt32(*opt_line) - script->line_offset();
|
||||
}
|
||||
|
||||
int32_t column = 0;
|
||||
if (!opt_column->IsNull(isolate) && !opt_column->IsUndefined(isolate)) {
|
||||
if (!opt_column->IsNullOrUndefined(isolate)) {
|
||||
CHECK(opt_column->IsNumber());
|
||||
column = NumberToInt32(*opt_column);
|
||||
if (line == 0) column -= script->column_offset();
|
||||
|
@ -19,7 +19,7 @@ MaybeHandle<Object> Runtime::GetObjectProperty(Isolate* isolate,
|
||||
Handle<Object> object,
|
||||
Handle<Object> key,
|
||||
bool* is_found_out) {
|
||||
if (object->IsUndefined(isolate) || object->IsNull(isolate)) {
|
||||
if (object->IsNullOrUndefined(isolate)) {
|
||||
THROW_NEW_ERROR(
|
||||
isolate,
|
||||
NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object),
|
||||
@ -199,7 +199,7 @@ RUNTIME_FUNCTION(Runtime_ObjectHasOwnProperty) {
|
||||
key_is_array_index
|
||||
? index < static_cast<uint32_t>(String::cast(*object)->length())
|
||||
: key->Equals(isolate->heap()->length_string()));
|
||||
} else if (object->IsNull(isolate) || object->IsUndefined(isolate)) {
|
||||
} else if (object->IsNullOrUndefined(isolate)) {
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject));
|
||||
}
|
||||
@ -276,7 +276,7 @@ MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
|
||||
Handle<Object> key,
|
||||
Handle<Object> value,
|
||||
LanguageMode language_mode) {
|
||||
if (object->IsUndefined(isolate) || object->IsNull(isolate)) {
|
||||
if (object->IsNullOrUndefined(isolate)) {
|
||||
THROW_NEW_ERROR(
|
||||
isolate,
|
||||
NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object),
|
||||
@ -618,7 +618,7 @@ RUNTIME_FUNCTION(Runtime_IsJSGlobalProxy) {
|
||||
}
|
||||
|
||||
static bool IsValidAccessor(Isolate* isolate, Handle<Object> obj) {
|
||||
return obj->IsUndefined(isolate) || obj->IsCallable() || obj->IsNull(isolate);
|
||||
return obj->IsNullOrUndefined(isolate) || obj->IsCallable();
|
||||
}
|
||||
|
||||
|
||||
@ -707,7 +707,7 @@ RUNTIME_FUNCTION(Runtime_GetConstructorName) {
|
||||
DCHECK_EQ(1, args.length());
|
||||
CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
|
||||
|
||||
CHECK(!object->IsUndefined(isolate) && !object->IsNull(isolate));
|
||||
CHECK(!object->IsNullOrUndefined(isolate));
|
||||
Handle<JSReceiver> recv = Object::ToObject(isolate, object).ToHandleChecked();
|
||||
return *JSReceiver::GetConstructorName(recv);
|
||||
}
|
||||
|
@ -1298,7 +1298,7 @@ MUST_USE_RESULT MaybeHandle<Object> SpeciesConstructor(
|
||||
JSObject::GetProperty(ctor, isolate->factory()->species_symbol()),
|
||||
Object);
|
||||
|
||||
if (species->IsNull(isolate) || species->IsUndefined(isolate)) {
|
||||
if (species->IsNullOrUndefined(isolate)) {
|
||||
return default_ctor;
|
||||
}
|
||||
|
||||
|
@ -481,8 +481,8 @@ void StringStream::PrintPrototype(JSFunction* fun, Object* receiver) {
|
||||
Object* name = fun->shared()->name();
|
||||
bool print_name = false;
|
||||
Isolate* isolate = fun->GetIsolate();
|
||||
if (receiver->IsNull(isolate) || receiver->IsUndefined(isolate) ||
|
||||
receiver->IsTheHole(isolate) || receiver->IsJSProxy()) {
|
||||
if (receiver->IsNullOrUndefined(isolate) || receiver->IsTheHole(isolate) ||
|
||||
receiver->IsJSProxy()) {
|
||||
print_name = true;
|
||||
} else if (isolate->context() != nullptr) {
|
||||
if (!receiver->IsJSObject()) {
|
||||
|
Loading…
Reference in New Issue
Block a user