mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(core/bindings): use is_instance_of_error() instead of is_native_error() (#12479)
This commit is contained in:
parent
d6062b2653
commit
e8ee5da459
5 changed files with 13 additions and 4 deletions
|
@ -1922,3 +1922,8 @@ itest!(eval_context_throw_with_conflicting_source {
|
|||
output: "eval_context_throw_with_conflicting_source.ts.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(eval_context_throw_dom_exception {
|
||||
args: "run eval_context_throw_dom_exception.js",
|
||||
output: "eval_context_throw_dom_exception.js.out",
|
||||
});
|
||||
|
|
2
cli/tests/testdata/eval_context_throw_dom_exception.js
vendored
Normal file
2
cli/tests/testdata/eval_context_throw_dom_exception.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
const [, errorInfo] = Deno.core.evalContext('throw new DOMException("foo")');
|
||||
console.log(errorInfo);
|
1
cli/tests/testdata/eval_context_throw_dom_exception.js.out
vendored
Normal file
1
cli/tests/testdata/eval_context_throw_dom_exception.js.out
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{ thrown: DOMException: foo, isNativeError: true, isCompileError: false }
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use crate::error::is_instance_of_error;
|
||||
use crate::error::AnyError;
|
||||
use crate::modules::ModuleMap;
|
||||
use crate::resolve_url_or_path;
|
||||
|
@ -238,7 +239,7 @@ pub extern "C" fn host_import_module_dynamically_callback(
|
|||
args: v8::FunctionCallbackArguments,
|
||||
_rv: v8::ReturnValue| {
|
||||
let arg = args.get(0);
|
||||
if arg.is_native_error() {
|
||||
if is_instance_of_error(scope, arg) {
|
||||
let message = v8::Exception::create_message(scope, arg);
|
||||
if message.get_stack_trace(scope).unwrap().get_frame_count() == 0 {
|
||||
let arg: v8::Local<v8::Object> = arg.try_into().unwrap();
|
||||
|
@ -512,7 +513,7 @@ fn eval_context(
|
|||
None,
|
||||
Some(ErrInfo {
|
||||
thrown: exception.into(),
|
||||
is_native_error: exception.is_native_error(),
|
||||
is_native_error: is_instance_of_error(tc_scope, exception),
|
||||
is_compile_error: true,
|
||||
}),
|
||||
);
|
||||
|
@ -529,7 +530,7 @@ fn eval_context(
|
|||
None,
|
||||
Some(ErrInfo {
|
||||
thrown: exception.into(),
|
||||
is_native_error: exception.is_native_error(),
|
||||
is_native_error: is_instance_of_error(tc_scope, exception),
|
||||
is_compile_error: false,
|
||||
}),
|
||||
);
|
||||
|
|
|
@ -297,7 +297,7 @@ pub(crate) fn attach_handle_to_error(
|
|||
/// of `instanceof`. `Value::is_native_error()` also checks for static class
|
||||
/// inheritance rather than just scanning the prototype chain, which doesn't
|
||||
/// work with our WebIDL implementation of `DOMException`.
|
||||
fn is_instance_of_error<'s>(
|
||||
pub(crate) fn is_instance_of_error<'s>(
|
||||
scope: &mut v8::HandleScope<'s>,
|
||||
value: v8::Local<v8::Value>,
|
||||
) -> bool {
|
||||
|
|
Loading…
Reference in a new issue