Skip to content

Commit a2dad04

Browse files
fhinkelCommit bot
authored andcommitted
Use JS_ERROR_TYPE to check for error objects.
Replace explicit Object::IsErrorObject() and v8::IsNativeError() with macro generated functions Object::IsJSError() and HeapObject::IsJSError(). BUG= Committed: https://crrev.com/90e4fd136387ca7271d8ea87f4fc667e4f55063b Cr-Commit-Position: refs/heads/master@{#37244} CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_chromium_rel_ng;tryserver.blink:linux_blink_rel Review-Url: https://codereview.chromium.org/2090333002 Cr-Commit-Position: refs/heads/master@{#37279}
1 parent cd18075 commit a2dad04

File tree

8 files changed

+130
-163
lines changed

8 files changed

+130
-163
lines changed

src/api.cc

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,22 +3005,7 @@ bool Value::IsUint32() const {
30053005

30063006

30073007
bool Value::IsNativeError() const {
3008-
i::Handle<i::Object> obj = Utils::OpenHandle(this);
3009-
if (!obj->IsJSObject()) return false;
3010-
i::Handle<i::JSObject> js_obj = i::Handle<i::JSObject>::cast(obj);
3011-
i::Isolate* isolate = js_obj->GetIsolate();
3012-
i::Handle<i::Object> constructor(js_obj->map()->GetConstructor(), isolate);
3013-
if (!constructor->IsJSFunction()) return false;
3014-
i::Handle<i::JSFunction> function =
3015-
i::Handle<i::JSFunction>::cast(constructor);
3016-
if (!function->shared()->native()) return false;
3017-
return function.is_identical_to(isolate->error_function()) ||
3018-
function.is_identical_to(isolate->eval_error_function()) ||
3019-
function.is_identical_to(isolate->range_error_function()) ||
3020-
function.is_identical_to(isolate->reference_error_function()) ||
3021-
function.is_identical_to(isolate->syntax_error_function()) ||
3022-
function.is_identical_to(isolate->type_error_function()) ||
3023-
function.is_identical_to(isolate->uri_error_function());
3008+
return Utils::OpenHandle(this)->IsJSError();
30243009
}
30253010

30263011

src/isolate.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception,
14541454
MessageLocation* location) {
14551455
Handle<JSArray> stack_trace_object;
14561456
if (capture_stack_trace_for_uncaught_exceptions_) {
1457-
if (Object::IsErrorObject(this, exception)) {
1457+
if (exception->IsJSError()) {
14581458
// We fetch the stack trace that corresponds to this error object.
14591459
// If the lookup fails, the exception is probably not a valid Error
14601460
// object. In that case, we fall through and capture the stack trace

src/messages.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void MessageHandler::ReportMessage(Isolate* isolate, MessageLocation* loc,
9898
MaybeHandle<Object> maybe_stringified;
9999
Handle<Object> stringified;
100100
// Make sure we don't leak uncaught internally generated Error objects.
101-
if (Object::IsErrorObject(isolate, argument)) {
101+
if (argument->IsJSError()) {
102102
Handle<Object> args[] = {argument};
103103
maybe_stringified = Execution::TryCall(
104104
isolate, isolate->no_side_effects_to_string_fun(),

src/objects-inl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ TYPE_CHECKER(Simd128Value, SIMD128_VALUE_TYPE)
156156
SIMD128_TYPES(SIMD128_TYPE_CHECKER)
157157
#undef SIMD128_TYPE_CHECKER
158158

159-
// TODO(cbruni): remove once all the isolate-based versions are in place.
160159
#define IS_TYPE_FUNCTION_DEF(type_) \
161160
bool Object::Is##type_() const { \
162161
return IsHeapObject() && HeapObject::cast(this)->Is##type_(); \
@@ -787,11 +786,12 @@ TYPE_CHECKER(Cell, CELL_TYPE)
787786
TYPE_CHECKER(PropertyCell, PROPERTY_CELL_TYPE)
788787
TYPE_CHECKER(WeakCell, WEAK_CELL_TYPE)
789788
TYPE_CHECKER(SharedFunctionInfo, SHARED_FUNCTION_INFO_TYPE)
789+
TYPE_CHECKER(JSDate, JS_DATE_TYPE)
790+
TYPE_CHECKER(JSError, JS_ERROR_TYPE)
790791
TYPE_CHECKER(JSGeneratorObject, JS_GENERATOR_OBJECT_TYPE)
792+
TYPE_CHECKER(JSMessageObject, JS_MESSAGE_OBJECT_TYPE)
791793
TYPE_CHECKER(JSModule, JS_MODULE_TYPE)
792794
TYPE_CHECKER(JSValue, JS_VALUE_TYPE)
793-
TYPE_CHECKER(JSDate, JS_DATE_TYPE)
794-
TYPE_CHECKER(JSMessageObject, JS_MESSAGE_OBJECT_TYPE)
795795

796796
bool HeapObject::IsAbstractCode() const {
797797
return IsBytecodeArray() || IsCode();

src/objects.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,18 +1321,6 @@ Maybe<bool> Object::SetPropertyWithDefinedSetter(Handle<Object> receiver,
13211321
}
13221322

13231323

1324-
// static
1325-
bool Object::IsErrorObject(Isolate* isolate, Handle<Object> object) {
1326-
if (!object->IsJSObject()) return false;
1327-
// Use stack_trace_symbol as proxy for [[ErrorData]].
1328-
Handle<Name> symbol = isolate->factory()->stack_trace_symbol();
1329-
Maybe<bool> has_stack_trace =
1330-
JSReceiver::HasOwnProperty(Handle<JSReceiver>::cast(object), symbol);
1331-
DCHECK(!has_stack_trace.IsNothing());
1332-
return has_stack_trace.FromJust();
1333-
}
1334-
1335-
13361324
// static
13371325
bool JSObject::AllCanRead(LookupIterator* it) {
13381326
// Skip current iteration, it's in state ACCESS_CHECK or INTERCEPTOR, both of

src/objects.h

Lines changed: 116 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -888,121 +888,122 @@ template <class C> inline bool Is(Object* obj);
888888
V(Primitive) \
889889
V(Number)
890890

891-
#define HEAP_OBJECT_TYPE_LIST(V) \
892-
V(HeapNumber) \
893-
V(MutableHeapNumber) \
894-
V(Simd128Value) \
895-
V(Float32x4) \
896-
V(Int32x4) \
897-
V(Uint32x4) \
898-
V(Bool32x4) \
899-
V(Int16x8) \
900-
V(Uint16x8) \
901-
V(Bool16x8) \
902-
V(Int8x16) \
903-
V(Uint8x16) \
904-
V(Bool8x16) \
905-
V(Name) \
906-
V(UniqueName) \
907-
V(String) \
908-
V(SeqString) \
909-
V(ExternalString) \
910-
V(ConsString) \
911-
V(SlicedString) \
912-
V(ExternalTwoByteString) \
913-
V(ExternalOneByteString) \
914-
V(SeqTwoByteString) \
915-
V(SeqOneByteString) \
916-
V(InternalizedString) \
917-
V(Symbol) \
918-
\
919-
V(FixedTypedArrayBase) \
920-
V(FixedUint8Array) \
921-
V(FixedInt8Array) \
922-
V(FixedUint16Array) \
923-
V(FixedInt16Array) \
924-
V(FixedUint32Array) \
925-
V(FixedInt32Array) \
926-
V(FixedFloat32Array) \
927-
V(FixedFloat64Array) \
928-
V(FixedUint8ClampedArray) \
929-
V(ByteArray) \
930-
V(BytecodeArray) \
931-
V(FreeSpace) \
932-
V(JSReceiver) \
933-
V(JSObject) \
934-
V(JSContextExtensionObject) \
935-
V(JSGeneratorObject) \
936-
V(JSModule) \
937-
V(Map) \
938-
V(DescriptorArray) \
939-
V(TransitionArray) \
940-
V(LiteralsArray) \
941-
V(TypeFeedbackMetadata) \
942-
V(TypeFeedbackVector) \
943-
V(DeoptimizationInputData) \
944-
V(DeoptimizationOutputData) \
945-
V(DependentCode) \
946-
V(HandlerTable) \
947-
V(FixedArray) \
948-
V(FixedDoubleArray) \
949-
V(WeakFixedArray) \
950-
V(ArrayList) \
951-
V(Context) \
952-
V(ScriptContextTable) \
953-
V(NativeContext) \
954-
V(ScopeInfo) \
955-
V(JSBoundFunction) \
956-
V(JSFunction) \
957-
V(Code) \
958-
V(AbstractCode) \
959-
V(Oddball) \
960-
V(SharedFunctionInfo) \
961-
V(JSValue) \
962-
V(JSDate) \
963-
V(JSMessageObject) \
964-
V(StringWrapper) \
965-
V(Foreign) \
966-
V(Boolean) \
967-
V(JSArray) \
968-
V(JSArrayBuffer) \
969-
V(JSArrayBufferView) \
970-
V(JSTypedArray) \
971-
V(JSDataView) \
972-
V(JSProxy) \
973-
V(JSSet) \
974-
V(JSMap) \
975-
V(JSSetIterator) \
976-
V(JSMapIterator) \
977-
V(JSWeakCollection) \
978-
V(JSWeakMap) \
979-
V(JSWeakSet) \
980-
V(JSRegExp) \
981-
V(HashTable) \
982-
V(Dictionary) \
983-
V(StringTable) \
984-
V(StringSet) \
985-
V(NormalizedMapCache) \
986-
V(CompilationCacheTable) \
987-
V(CodeCacheHashTable) \
988-
V(MapCache) \
989-
V(JSGlobalObject) \
990-
V(JSGlobalProxy) \
991-
V(Undetectable) \
992-
V(AccessCheckNeeded) \
993-
V(Callable) \
994-
V(Function) \
995-
V(Constructor) \
996-
V(TemplateInfo) \
997-
V(Filler) \
998-
V(FixedArrayBase) \
999-
V(External) \
1000-
V(Struct) \
1001-
V(Cell) \
1002-
V(PropertyCell) \
1003-
V(WeakCell) \
1004-
V(ObjectHashTable) \
1005-
V(WeakHashTable) \
891+
#define HEAP_OBJECT_TYPE_LIST(V) \
892+
V(HeapNumber) \
893+
V(MutableHeapNumber) \
894+
V(Simd128Value) \
895+
V(Float32x4) \
896+
V(Int32x4) \
897+
V(Uint32x4) \
898+
V(Bool32x4) \
899+
V(Int16x8) \
900+
V(Uint16x8) \
901+
V(Bool16x8) \
902+
V(Int8x16) \
903+
V(Uint8x16) \
904+
V(Bool8x16) \
905+
V(Name) \
906+
V(UniqueName) \
907+
V(String) \
908+
V(SeqString) \
909+
V(ExternalString) \
910+
V(ConsString) \
911+
V(SlicedString) \
912+
V(ExternalTwoByteString) \
913+
V(ExternalOneByteString) \
914+
V(SeqTwoByteString) \
915+
V(SeqOneByteString) \
916+
V(InternalizedString) \
917+
V(Symbol) \
918+
\
919+
V(FixedTypedArrayBase) \
920+
V(FixedUint8Array) \
921+
V(FixedInt8Array) \
922+
V(FixedUint16Array) \
923+
V(FixedInt16Array) \
924+
V(FixedUint32Array) \
925+
V(FixedInt32Array) \
926+
V(FixedFloat32Array) \
927+
V(FixedFloat64Array) \
928+
V(FixedUint8ClampedArray) \
929+
V(ByteArray) \
930+
V(BytecodeArray) \
931+
V(FreeSpace) \
932+
V(JSReceiver) \
933+
V(JSObject) \
934+
V(JSContextExtensionObject) \
935+
V(JSGeneratorObject) \
936+
V(JSModule) \
937+
V(Map) \
938+
V(DescriptorArray) \
939+
V(TransitionArray) \
940+
V(LiteralsArray) \
941+
V(TypeFeedbackMetadata) \
942+
V(TypeFeedbackVector) \
943+
V(DeoptimizationInputData) \
944+
V(DeoptimizationOutputData) \
945+
V(DependentCode) \
946+
V(HandlerTable) \
947+
V(FixedArray) \
948+
V(FixedDoubleArray) \
949+
V(WeakFixedArray) \
950+
V(ArrayList) \
951+
V(Context) \
952+
V(ScriptContextTable) \
953+
V(NativeContext) \
954+
V(ScopeInfo) \
955+
V(JSBoundFunction) \
956+
V(JSFunction) \
957+
V(Code) \
958+
V(AbstractCode) \
959+
V(Oddball) \
960+
V(SharedFunctionInfo) \
961+
V(JSValue) \
962+
V(JSDate) \
963+
V(JSMessageObject) \
964+
V(StringWrapper) \
965+
V(Foreign) \
966+
V(Boolean) \
967+
V(JSArray) \
968+
V(JSArrayBuffer) \
969+
V(JSArrayBufferView) \
970+
V(JSTypedArray) \
971+
V(JSDataView) \
972+
V(JSProxy) \
973+
V(JSError) \
974+
V(JSSet) \
975+
V(JSMap) \
976+
V(JSSetIterator) \
977+
V(JSMapIterator) \
978+
V(JSWeakCollection) \
979+
V(JSWeakMap) \
980+
V(JSWeakSet) \
981+
V(JSRegExp) \
982+
V(HashTable) \
983+
V(Dictionary) \
984+
V(StringTable) \
985+
V(StringSet) \
986+
V(NormalizedMapCache) \
987+
V(CompilationCacheTable) \
988+
V(CodeCacheHashTable) \
989+
V(MapCache) \
990+
V(JSGlobalObject) \
991+
V(JSGlobalProxy) \
992+
V(Undetectable) \
993+
V(AccessCheckNeeded) \
994+
V(Callable) \
995+
V(Function) \
996+
V(Constructor) \
997+
V(TemplateInfo) \
998+
V(Filler) \
999+
V(FixedArrayBase) \
1000+
V(External) \
1001+
V(Struct) \
1002+
V(Cell) \
1003+
V(PropertyCell) \
1004+
V(WeakCell) \
1005+
V(ObjectHashTable) \
1006+
V(WeakHashTable) \
10061007
V(OrderedHashTable)
10071008

10081009
#define ODDBALL_LIST(V) \
@@ -1189,9 +1190,6 @@ class Object {
11891190
MUST_USE_RESULT static MaybeHandle<Object> GetLengthFromArrayLike(
11901191
Isolate* isolate, Handle<Object> object);
11911192

1192-
// Check whether |object| is an instance of Error or NativeError.
1193-
static bool IsErrorObject(Isolate* isolate, Handle<Object> object);
1194-
11951193
// ES6 section 12.5.6 The typeof Operator
11961194
static Handle<String> TypeOf(Isolate* isolate, Handle<Object> object);
11971195

test/cctest/wasm/test-wasm-stack.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ struct ExceptionInfo {
5151
};
5252

5353
template <int N>
54-
void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc,
54+
void CheckExceptionInfos(Handle<Object> exc,
5555
const ExceptionInfo (&excInfos)[N]) {
5656
// Check that it's indeed an Error object.
57-
CHECK(Object::IsErrorObject(isolate, exc));
57+
CHECK(exc->IsJSError());
5858

5959
// Extract stack frame from the exception.
6060
Local<v8::Value> localExc = Utils::ToLocal(exc);
@@ -118,8 +118,7 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
118118
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 2}, // -
119119
{"callFn", 1, 24} // -
120120
};
121-
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
122-
expected_exceptions);
121+
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
123122
}
124123

125124
// Trigger a trap in WASM, stack should be JS -> WASM -> WASM.
@@ -161,6 +160,5 @@ TEST(CollectDetailedWasmStack_WasmError) {
161160
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 2}, // -
162161
{"callFn", 1, 24} //-
163162
};
164-
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
165-
expected_exceptions);
163+
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
166164
}

test/cctest/wasm/test-wasm-trap-position.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ struct ExceptionInfo {
3838
};
3939

4040
template <int N>
41-
void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc,
41+
void CheckExceptionInfos(Handle<Object> exc,
4242
const ExceptionInfo (&excInfos)[N]) {
4343
// Check that it's indeed an Error object.
44-
CHECK(Object::IsErrorObject(isolate, exc));
44+
CHECK(exc->IsJSError());
4545

4646
// Extract stack frame from the exception.
4747
Local<v8::Value> localExc = Utils::ToLocal(exc);
@@ -93,8 +93,7 @@ TEST(Unreachable) {
9393
{"<WASM UNNAMED>", static_cast<int>(wasm_index), 2}, // --
9494
{"callFn", 1, 24} // --
9595
};
96-
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
97-
expected_exceptions);
96+
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
9897
}
9998

10099
// Trigger a trap for loading from out-of-bounds.
@@ -136,6 +135,5 @@ TEST(IllegalLoad) {
136135
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 3}, // --
137136
{"callFn", 1, 24} // --
138137
};
139-
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
140-
expected_exceptions);
138+
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
141139
}

0 commit comments

Comments
 (0)