-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for js getters and setters
- Loading branch information
1 parent
b4526b7
commit a57858a
Showing
5 changed files
with
304 additions
and
47 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::web_executor::js::{JSContext, JSFunction, JSFunctionVariadic, JSValue}; | ||
|
||
pub trait JSObject { | ||
type Value: JSValue; | ||
type Function: JSFunction; | ||
type FunctionVariadic: JSFunctionVariadic; | ||
type GetterCB: JSGetterCallback; | ||
type SetterCB: JSSetterCallback; | ||
|
||
fn set_property(&self, name: &str, value: &Self::Value) -> crate::types::Result<()>; | ||
|
||
fn get_property(&self, name: &str) -> crate::types::Result<Self::Value>; | ||
|
||
fn call_method(&self, name: &str, args: &[&Self::Value]) -> crate::types::Result<Self::Value>; | ||
|
||
fn set_method(&self, name: &str, func: &Self::Function) -> crate::types::Result<()>; | ||
|
||
fn set_method_variadic( | ||
&self, | ||
name: &str, | ||
func: &Self::FunctionVariadic, | ||
) -> crate::types::Result<()>; | ||
|
||
#[allow(clippy::type_complexity)] | ||
fn set_property_accessor( | ||
&self, | ||
name: &str, | ||
getter: Box<dyn Fn(&mut Self::GetterCB)>, | ||
setter: Box<dyn Fn(&mut Self::SetterCB)>, | ||
) -> crate::types::Result<()>; | ||
} | ||
|
||
pub trait JSGetterCallback { | ||
type Value: JSValue; | ||
type Context: JSContext; | ||
|
||
fn context(&mut self) -> &mut Self::Context; | ||
fn ret(&mut self, value: Self::Value); | ||
} | ||
|
||
pub trait JSSetterCallback { | ||
type Value: JSValue; | ||
type Context: JSContext; | ||
|
||
fn context(&mut self) -> &mut Self::Context; | ||
fn value(&mut self) -> &Self::Value; | ||
} |
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.