Skip to content

Commit

Permalink
Separate native and JavaScript functions (#3322)
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Oct 3, 2023
1 parent ceaaec7 commit 7445367
Show file tree
Hide file tree
Showing 15 changed files with 662 additions and 703 deletions.
18 changes: 6 additions & 12 deletions boa_cli/src/debug/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,11 @@ fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> Js

let Some(function) = object.as_function() else {
return Err(JsNativeError::typ()
.with_message("expected function object")
.with_message("expected an ordinary function object")
.into());
};

let code = function.codeblock().ok_or_else(|| {
JsNativeError::typ().with_message("native functions do not have bytecode")
})?;
let code = function.codeblock();

let mut graph = Graph::new(direction);
code.to_graph(context.interner(), graph.subgraph(String::default()));
Expand All @@ -118,12 +116,10 @@ fn bytecode(_: &JsValue, args: &[JsValue], context: &mut Context<'_>) -> JsResul
let object = object.borrow();
let Some(function) = object.as_function() else {
return Err(JsNativeError::typ()
.with_message("expected function object")
.with_message("expected an ordinary function object")
.into());
};
let code = function.codeblock().ok_or_else(|| {
JsNativeError::typ().with_message("native functions do not have bytecode")
})?;
let code = function.codeblock();

Ok(js_string!(code.to_interned_string(context.interner())).into())
}
Expand All @@ -132,12 +128,10 @@ fn set_trace_flag_in_function_object(object: &JsObject, value: bool) -> JsResult
let object = object.borrow();
let Some(function) = object.as_function() else {
return Err(JsNativeError::typ()
.with_message("expected function object")
.with_message("expected an ordinary function object")
.into());
};
let code = function.codeblock().ok_or_else(|| {
JsNativeError::typ().with_message("native functions do not have bytecode")
})?;
let code = function.codeblock();
code.set_traceable(value);
Ok(())
}
Expand Down
17 changes: 6 additions & 11 deletions boa_engine/src/builtins/error/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError
use crate::{
builtins::{
function::{Function, FunctionKind},
BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject,
},
builtins::{BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject},
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
error::JsNativeError,
js_string,
Expand Down Expand Up @@ -136,13 +133,11 @@ impl IntrinsicObject for ThrowTypeError {
let mut obj = obj.borrow_mut();

obj.extensible = false;
*obj.kind_mut() = ObjectKind::Function(Function::new(
FunctionKind::Native {
function: NativeFunction::from_fn_ptr(throw_type_error),
constructor: None,
},
realm.clone(),
));
*obj.kind_mut() = ObjectKind::NativeFunction {
function: NativeFunction::from_fn_ptr(throw_type_error),
constructor: None,
realm: realm.clone(),
}
}

fn get(intrinsics: &Intrinsics) -> JsObject {
Expand Down
Loading

0 comments on commit 7445367

Please sign in to comment.