-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
op2 object wraps #805
Open
littledivy
wants to merge
19
commits into
denoland:main
Choose a base branch
from
littledivy:op2++_rework
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+524
−52
Open
op2 object wraps #805
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
24e398c
op2++ rework 1
littledivy f042625
Static members
littledivy 7e38d08
some cleanup
littledivy b5a43d2
Refactor
littledivy a105ac9
Add some comments
littledivy 4d0bd64
x
littledivy 58d65fd
Tests
littledivy f414158
Fixl int
littledivy 19e91c6
Update core/cppgc.rs
littledivy 774f379
perf: use isolate instead of scope
littledivy 54aa520
fix
littledivy 3ecd6b3
reviews
littledivy a003606
x
littledivy b9cdc79
Merge
littledivy 48ea286
x
littledivy 76b9ab2
x
littledivy 46612e0
Merge
littledivy f0725dd
Fix
littledivy b2cd2ea
x
littledivy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,10 +168,22 @@ pub type GlobalObjectMiddlewareFn = | |
|
||
extern "C" fn noop() {} | ||
|
||
// Delcration for object wrappers. | ||
littledivy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[derive(Clone, Copy)] | ||
pub struct OpMethodDecl { | ||
// TypeId::of::<T>() is unstable-nightly in const context so | ||
// we store the fn pointer instead. | ||
pub id: fn() -> std::any::TypeId, | ||
Comment on lines
+182
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please open an issue to migrate to |
||
pub name: (&'static str, FastStaticString), | ||
pub constructor: OpDecl, | ||
pub methods: &'static [OpDecl], | ||
pub static_methods: &'static [OpDecl], | ||
} | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct OpDecl { | ||
pub name: &'static str, | ||
pub(crate) name_fast: FastStaticString, | ||
pub name_fast: FastStaticString, | ||
pub is_async: bool, | ||
pub is_reentrant: bool, | ||
pub arg_count: u8, | ||
|
@@ -391,6 +403,7 @@ macro_rules! extension { | |
$(, bounds = [ $( $bound:path : $bound_type:ident ),+ ] )? | ||
$(, ops_fn = $ops_symbol:ident $( < $ops_param:ident > )? )? | ||
$(, ops = [ $( $(#[$m:meta])* $( $op:ident )::+ $( < $( $op_param:ident ),* > )? ),+ $(,)? ] )? | ||
$(, objects = [ $( $object:ident )::+ ] )? | ||
$(, esm_entry_point = $esm_entry_point:expr )? | ||
$(, esm = [ $($esm:tt)* ] )? | ||
$(, lazy_loaded_esm = [ $($lazy_loaded_esm:tt)* ] )? | ||
|
@@ -454,6 +467,9 @@ macro_rules! extension { | |
$( #[ $m ] )* | ||
$( $op )::+ $( :: < $($op_param),* > )? () | ||
}),+)?]), | ||
objects: ::std::borrow::Cow::Borrowed(&[ | ||
$( $( $object )::+::DECL, )* | ||
]), | ||
external_references: ::std::borrow::Cow::Borrowed(&[ $( $external_reference ),* ]), | ||
global_template_middleware: ::std::option::Option::None, | ||
global_object_middleware: ::std::option::Option::None, | ||
|
@@ -587,6 +603,7 @@ pub struct Extension { | |
pub lazy_loaded_esm_files: Cow<'static, [ExtensionFileSource]>, | ||
pub esm_entry_point: Option<&'static str>, | ||
pub ops: Cow<'static, [OpDecl]>, | ||
pub objects: Cow<'static, [OpMethodDecl]>, | ||
pub external_references: Cow<'static, [v8::ExternalReference<'static>]>, | ||
pub global_template_middleware: Option<GlobalTemplateMiddlewareFn>, | ||
pub global_object_middleware: Option<GlobalObjectMiddlewareFn>, | ||
|
@@ -610,6 +627,7 @@ impl Extension { | |
lazy_loaded_esm_files: Cow::Borrowed(&[]), | ||
esm_entry_point: None, | ||
ops: self.ops.clone(), | ||
objects: self.objects.clone(), | ||
external_references: self.external_references.clone(), | ||
global_template_middleware: self.global_template_middleware, | ||
global_object_middleware: self.global_object_middleware, | ||
|
@@ -628,6 +646,7 @@ impl Default for Extension { | |
lazy_loaded_esm_files: Cow::Borrowed(&[]), | ||
esm_entry_point: None, | ||
ops: Cow::Borrowed(&[]), | ||
objects: Cow::Borrowed(&[]), | ||
external_references: Cow::Borrowed(&[]), | ||
global_template_middleware: None, | ||
global_object_middleware: None, | ||
|
@@ -692,6 +711,11 @@ impl Extension { | |
self.ops.as_ref() | ||
} | ||
|
||
/// Called at JsRuntime startup to initialize method ops in the isolate. | ||
pub fn init_method_ops(&self) -> &[OpMethodDecl] { | ||
self.objects.as_ref() | ||
} | ||
|
||
/// Allows setting up the initial op-state of an isolate at startup. | ||
pub fn take_state(&mut self, state: &mut OpState) { | ||
if let Some(op_fn) = self.op_state_fn.take() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good solution. @devsnek thoughts?