Commit f0a03f0b authored by machenbach's avatar machenbach Committed by Commit bot

Revert of Use instance type in Object::IsErrorObject(). (patchset #9 id:160001...

Revert of Use instance type in Object::IsErrorObject(). (patchset #9 id:160001 of https://codereview.chromium.org/2090333002/ )

Reason for revert:
[Sheriff] Breaks layout tests:
https://build.chromium.org/p/client.v8.fyi/builders/V8-Blink%20Linux%2064/builds/7700

Please rebase upstream first if intended.

Original issue's description:
> Use JS_ERROR_TYPE to check for error objects.
>
> Replace explicit Object::IsErrorObject() with macro generated functions Object::IsJSError() and HeapObject::IsJSError().
>
> BUG=
>
> Committed: https://crrev.com/90e4fd136387ca7271d8ea87f4fc667e4f55063b
> Cr-Commit-Position: refs/heads/master@{#37244}

TBR=verwaest@chromium.org,jochen@chromium.org,franzih@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review-Url: https://codereview.chromium.org/2092083002
Cr-Commit-Position: refs/heads/master@{#37250}
parent 8349651e
......@@ -3005,7 +3005,22 @@ bool Value::IsUint32() const {
bool Value::IsNativeError() const {
return Utils::OpenHandle(this)->IsJSError();
i::Handle<i::Object> obj = Utils::OpenHandle(this);
if (!obj->IsJSObject()) return false;
i::Handle<i::JSObject> js_obj = i::Handle<i::JSObject>::cast(obj);
i::Isolate* isolate = js_obj->GetIsolate();
i::Handle<i::Object> constructor(js_obj->map()->GetConstructor(), isolate);
if (!constructor->IsJSFunction()) return false;
i::Handle<i::JSFunction> function =
i::Handle<i::JSFunction>::cast(constructor);
if (!function->shared()->native()) return false;
return function.is_identical_to(isolate->error_function()) ||
function.is_identical_to(isolate->eval_error_function()) ||
function.is_identical_to(isolate->range_error_function()) ||
function.is_identical_to(isolate->reference_error_function()) ||
function.is_identical_to(isolate->syntax_error_function()) ||
function.is_identical_to(isolate->type_error_function()) ||
function.is_identical_to(isolate->uri_error_function());
}
......
......@@ -1454,7 +1454,7 @@ Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception,
MessageLocation* location) {
Handle<JSArray> stack_trace_object;
if (capture_stack_trace_for_uncaught_exceptions_) {
if (exception->IsJSError()) {
if (Object::IsErrorObject(this, exception)) {
// We fetch the stack trace that corresponds to this error object.
// If the lookup fails, the exception is probably not a valid Error
// object. In that case, we fall through and capture the stack trace
......
......@@ -98,7 +98,7 @@ void MessageHandler::ReportMessage(Isolate* isolate, MessageLocation* loc,
MaybeHandle<Object> maybe_stringified;
Handle<Object> stringified;
// Make sure we don't leak uncaught internally generated Error objects.
if (argument->IsJSError()) {
if (Object::IsErrorObject(isolate, argument)) {
Handle<Object> args[] = {argument};
maybe_stringified = Execution::TryCall(
isolate, isolate->no_side_effects_to_string_fun(),
......
......@@ -156,6 +156,7 @@ TYPE_CHECKER(Simd128Value, SIMD128_VALUE_TYPE)
SIMD128_TYPES(SIMD128_TYPE_CHECKER)
#undef SIMD128_TYPE_CHECKER
// TODO(cbruni): remove once all the isolate-based versions are in place.
#define IS_TYPE_FUNCTION_DEF(type_) \
bool Object::Is##type_() const { \
return IsHeapObject() && HeapObject::cast(this)->Is##type_(); \
......@@ -786,12 +787,11 @@ TYPE_CHECKER(Cell, CELL_TYPE)
TYPE_CHECKER(PropertyCell, PROPERTY_CELL_TYPE)
TYPE_CHECKER(WeakCell, WEAK_CELL_TYPE)
TYPE_CHECKER(SharedFunctionInfo, SHARED_FUNCTION_INFO_TYPE)
TYPE_CHECKER(JSDate, JS_DATE_TYPE)
TYPE_CHECKER(JSError, JS_ERROR_TYPE)
TYPE_CHECKER(JSGeneratorObject, JS_GENERATOR_OBJECT_TYPE)
TYPE_CHECKER(JSMessageObject, JS_MESSAGE_OBJECT_TYPE)
TYPE_CHECKER(JSModule, JS_MODULE_TYPE)
TYPE_CHECKER(JSValue, JS_VALUE_TYPE)
TYPE_CHECKER(JSDate, JS_DATE_TYPE)
TYPE_CHECKER(JSMessageObject, JS_MESSAGE_OBJECT_TYPE)
bool HeapObject::IsAbstractCode() const {
return IsBytecodeArray() || IsCode();
......
......@@ -1286,6 +1286,18 @@ Maybe<bool> Object::SetPropertyWithDefinedSetter(Handle<Object> receiver,
}
// static
bool Object::IsErrorObject(Isolate* isolate, Handle<Object> object) {
if (!object->IsJSObject()) return false;
// Use stack_trace_symbol as proxy for [[ErrorData]].
Handle<Name> symbol = isolate->factory()->stack_trace_symbol();
Maybe<bool> has_stack_trace =
JSReceiver::HasOwnProperty(Handle<JSReceiver>::cast(object), symbol);
DCHECK(!has_stack_trace.IsNothing());
return has_stack_trace.FromJust();
}
// static
bool JSObject::AllCanRead(LookupIterator* it) {
// Skip current iteration, it's in state ACCESS_CHECK or INTERCEPTOR, both of
......
......@@ -888,122 +888,121 @@ template <class C> inline bool Is(Object* obj);
V(Primitive) \
V(Number)
#define HEAP_OBJECT_TYPE_LIST(V) \
V(HeapNumber) \
V(MutableHeapNumber) \
V(Simd128Value) \
V(Float32x4) \
V(Int32x4) \
V(Uint32x4) \
V(Bool32x4) \
V(Int16x8) \
V(Uint16x8) \
V(Bool16x8) \
V(Int8x16) \
V(Uint8x16) \
V(Bool8x16) \
V(Name) \
V(UniqueName) \
V(String) \
V(SeqString) \
V(ExternalString) \
V(ConsString) \
V(SlicedString) \
V(ExternalTwoByteString) \
V(ExternalOneByteString) \
V(SeqTwoByteString) \
V(SeqOneByteString) \
V(InternalizedString) \
V(Symbol) \
\
V(FixedTypedArrayBase) \
V(FixedUint8Array) \
V(FixedInt8Array) \
V(FixedUint16Array) \
V(FixedInt16Array) \
V(FixedUint32Array) \
V(FixedInt32Array) \
V(FixedFloat32Array) \
V(FixedFloat64Array) \
V(FixedUint8ClampedArray) \
V(ByteArray) \
V(BytecodeArray) \
V(FreeSpace) \
V(JSReceiver) \
V(JSObject) \
V(JSContextExtensionObject) \
V(JSGeneratorObject) \
V(JSModule) \
V(Map) \
V(DescriptorArray) \
V(TransitionArray) \
V(LiteralsArray) \
V(TypeFeedbackMetadata) \
V(TypeFeedbackVector) \
V(DeoptimizationInputData) \
V(DeoptimizationOutputData) \
V(DependentCode) \
V(HandlerTable) \
V(FixedArray) \
V(FixedDoubleArray) \
V(WeakFixedArray) \
V(ArrayList) \
V(Context) \
V(ScriptContextTable) \
V(NativeContext) \
V(ScopeInfo) \
V(JSBoundFunction) \
V(JSFunction) \
V(Code) \
V(AbstractCode) \
V(Oddball) \
V(SharedFunctionInfo) \
V(JSValue) \
V(JSDate) \
V(JSMessageObject) \
V(StringWrapper) \
V(Foreign) \
V(Boolean) \
V(JSArray) \
V(JSArrayBuffer) \
V(JSArrayBufferView) \
V(JSTypedArray) \
V(JSDataView) \
V(JSProxy) \
V(JSError) \
V(JSSet) \
V(JSMap) \
V(JSSetIterator) \
V(JSMapIterator) \
V(JSWeakCollection) \
V(JSWeakMap) \
V(JSWeakSet) \
V(JSRegExp) \
V(HashTable) \
V(Dictionary) \
V(StringTable) \
V(StringSet) \
V(NormalizedMapCache) \
V(CompilationCacheTable) \
V(CodeCacheHashTable) \
V(MapCache) \
V(JSGlobalObject) \
V(JSGlobalProxy) \
V(Undetectable) \
V(AccessCheckNeeded) \
V(Callable) \
V(Function) \
V(Constructor) \
V(TemplateInfo) \
V(Filler) \
V(FixedArrayBase) \
V(External) \
V(Struct) \
V(Cell) \
V(PropertyCell) \
V(WeakCell) \
V(ObjectHashTable) \
V(WeakHashTable) \
#define HEAP_OBJECT_TYPE_LIST(V) \
V(HeapNumber) \
V(MutableHeapNumber) \
V(Simd128Value) \
V(Float32x4) \
V(Int32x4) \
V(Uint32x4) \
V(Bool32x4) \
V(Int16x8) \
V(Uint16x8) \
V(Bool16x8) \
V(Int8x16) \
V(Uint8x16) \
V(Bool8x16) \
V(Name) \
V(UniqueName) \
V(String) \
V(SeqString) \
V(ExternalString) \
V(ConsString) \
V(SlicedString) \
V(ExternalTwoByteString) \
V(ExternalOneByteString) \
V(SeqTwoByteString) \
V(SeqOneByteString) \
V(InternalizedString) \
V(Symbol) \
\
V(FixedTypedArrayBase) \
V(FixedUint8Array) \
V(FixedInt8Array) \
V(FixedUint16Array) \
V(FixedInt16Array) \
V(FixedUint32Array) \
V(FixedInt32Array) \
V(FixedFloat32Array) \
V(FixedFloat64Array) \
V(FixedUint8ClampedArray) \
V(ByteArray) \
V(BytecodeArray) \
V(FreeSpace) \
V(JSReceiver) \
V(JSObject) \
V(JSContextExtensionObject) \
V(JSGeneratorObject) \
V(JSModule) \
V(Map) \
V(DescriptorArray) \
V(TransitionArray) \
V(LiteralsArray) \
V(TypeFeedbackMetadata) \
V(TypeFeedbackVector) \
V(DeoptimizationInputData) \
V(DeoptimizationOutputData) \
V(DependentCode) \
V(HandlerTable) \
V(FixedArray) \
V(FixedDoubleArray) \
V(WeakFixedArray) \
V(ArrayList) \
V(Context) \
V(ScriptContextTable) \
V(NativeContext) \
V(ScopeInfo) \
V(JSBoundFunction) \
V(JSFunction) \
V(Code) \
V(AbstractCode) \
V(Oddball) \
V(SharedFunctionInfo) \
V(JSValue) \
V(JSDate) \
V(JSMessageObject) \
V(StringWrapper) \
V(Foreign) \
V(Boolean) \
V(JSArray) \
V(JSArrayBuffer) \
V(JSArrayBufferView) \
V(JSTypedArray) \
V(JSDataView) \
V(JSProxy) \
V(JSSet) \
V(JSMap) \
V(JSSetIterator) \
V(JSMapIterator) \
V(JSWeakCollection) \
V(JSWeakMap) \
V(JSWeakSet) \
V(JSRegExp) \
V(HashTable) \
V(Dictionary) \
V(StringTable) \
V(StringSet) \
V(NormalizedMapCache) \
V(CompilationCacheTable) \
V(CodeCacheHashTable) \
V(MapCache) \
V(JSGlobalObject) \
V(JSGlobalProxy) \
V(Undetectable) \
V(AccessCheckNeeded) \
V(Callable) \
V(Function) \
V(Constructor) \
V(TemplateInfo) \
V(Filler) \
V(FixedArrayBase) \
V(External) \
V(Struct) \
V(Cell) \
V(PropertyCell) \
V(WeakCell) \
V(ObjectHashTable) \
V(WeakHashTable) \
V(OrderedHashTable)
#define ODDBALL_LIST(V) \
......@@ -1190,6 +1189,9 @@ class Object {
MUST_USE_RESULT static MaybeHandle<Object> GetLengthFromArrayLike(
Isolate* isolate, Handle<Object> object);
// Check whether |object| is an instance of Error or NativeError.
static bool IsErrorObject(Isolate* isolate, Handle<Object> object);
// ES6 section 12.5.6 The typeof Operator
static Handle<String> TypeOf(Isolate* isolate, Handle<Object> object);
......
......@@ -51,10 +51,10 @@ struct ExceptionInfo {
};
template <int N>
void CheckExceptionInfos(Handle<Object> exc,
void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc,
const ExceptionInfo (&excInfos)[N]) {
// Check that it's indeed an Error object.
CHECK(exc->IsJSError());
CHECK(Object::IsErrorObject(isolate, exc));
// Extract stack frame from the exception.
Local<v8::Value> localExc = Utils::ToLocal(exc);
......@@ -118,7 +118,8 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 2}, // -
{"callFn", 1, 24} // -
};
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
expected_exceptions);
}
// Trigger a trap in WASM, stack should be JS -> WASM -> WASM.
......@@ -160,5 +161,6 @@ TEST(CollectDetailedWasmStack_WasmError) {
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 2}, // -
{"callFn", 1, 24} //-
};
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
expected_exceptions);
}
......@@ -38,10 +38,10 @@ struct ExceptionInfo {
};
template <int N>
void CheckExceptionInfos(Handle<Object> exc,
void CheckExceptionInfos(Isolate* isolate, Handle<Object> exc,
const ExceptionInfo (&excInfos)[N]) {
// Check that it's indeed an Error object.
CHECK(exc->IsJSError());
CHECK(Object::IsErrorObject(isolate, exc));
// Extract stack frame from the exception.
Local<v8::Value> localExc = Utils::ToLocal(exc);
......@@ -93,7 +93,8 @@ TEST(Unreachable) {
{"<WASM UNNAMED>", static_cast<int>(wasm_index), 2}, // --
{"callFn", 1, 24} // --
};
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
expected_exceptions);
}
// Trigger a trap for loading from out-of-bounds.
......@@ -135,5 +136,6 @@ TEST(IllegalLoad) {
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2), 3}, // --
{"callFn", 1, 24} // --
};
CheckExceptionInfos(maybe_exc.ToHandleChecked(), expected_exceptions);
CheckExceptionInfos(isolate, maybe_exc.ToHandleChecked(),
expected_exceptions);
}
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