Skip to content

Commit

Permalink
Separate native and JavaScript functions
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Sep 29, 2023
1 parent 6e0ab82 commit 4f96143
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 575 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 @@ -82,13 +82,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 @@ -115,12 +113,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(code.to_interned_string(context.interner()).into())
}
Expand All @@ -129,12 +125,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,
object::{internal_methods::get_prototype_from_constructor, JsObject, ObjectData, ObjectKind},
Expand Down Expand Up @@ -135,13 +132,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 4f96143

Please sign in to comment.