0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-29 08:58:01 -04:00

fix(core/bindings): use is_instance_of_error() instead of is_native_error() (#12479)

This commit is contained in:
Nayeem Rahman 2021-10-19 17:26:45 +01:00 committed by GitHub
parent d6062b2653
commit e8ee5da459
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 4 deletions

View file

@ -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",
});

View file

@ -0,0 +1,2 @@
const [, errorInfo] = Deno.core.evalContext('throw new DOMException("foo")');
console.log(errorInfo);

View file

@ -0,0 +1 @@
{ thrown: DOMException: foo, isNativeError: true, isCompileError: false }

View file

@ -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,
}),
);

View file

@ -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 {