mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-25 08:39:15 -05:00
Remove 'context' param from (almost) all public methods (#406)
This commit is contained in:
parent
de2cca4c7f
commit
b1a4dfea8b
12 changed files with 325 additions and 286 deletions
|
@ -183,9 +183,12 @@ impl Message {
|
|||
pub fn get_source_line<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'s, String>> {
|
||||
unsafe { scope.cast_local(|_| v8__Message__GetSourceLine(self, &*context)) }
|
||||
unsafe {
|
||||
scope.cast_local(|sd| {
|
||||
v8__Message__GetSourceLine(self, sd.get_current_context())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the resource name for the script from where the function causing
|
||||
|
@ -198,8 +201,10 @@ impl Message {
|
|||
}
|
||||
|
||||
/// Returns the number, 1-based, of the line where the error occurred.
|
||||
pub fn get_line_number(&self, context: Local<Context>) -> Option<usize> {
|
||||
let i = unsafe { v8__Message__GetLineNumber(self, &*context) };
|
||||
pub fn get_line_number(&self, scope: &mut HandleScope) -> Option<usize> {
|
||||
let i = unsafe {
|
||||
v8__Message__GetLineNumber(self, &*scope.get_current_context())
|
||||
};
|
||||
if i < 0 {
|
||||
None
|
||||
} else {
|
||||
|
|
|
@ -264,11 +264,12 @@ impl Function {
|
|||
/// for a given FunctionCallback.
|
||||
pub fn new<'s>(
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
callback: impl MapFnTo<FunctionCallback>,
|
||||
) -> Option<Local<'s, Function>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| v8__Function__New(&*context, callback.map_fn_to()))
|
||||
scope.cast_local(|sd| {
|
||||
v8__Function__New(sd.get_current_context(), callback.map_fn_to())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,13 +277,16 @@ impl Function {
|
|||
/// for a given FunctionCallback and associated data.
|
||||
pub fn new_with_data<'s>(
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
data: Local<Value>,
|
||||
callback: impl MapFnTo<FunctionCallback>,
|
||||
) -> Option<Local<'s, Function>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| {
|
||||
v8__Function__NewWithData(&*context, callback.map_fn_to(), &*data)
|
||||
scope.cast_local(|sd| {
|
||||
v8__Function__NewWithData(
|
||||
sd.get_current_context(),
|
||||
callback.map_fn_to(),
|
||||
&*data,
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +294,6 @@ impl Function {
|
|||
pub fn call<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
recv: Local<Value>,
|
||||
args: &[Local<Value>],
|
||||
) -> Option<Local<'s, Value>> {
|
||||
|
@ -298,8 +301,9 @@ impl Function {
|
|||
let argc = int::try_from(args.len()).unwrap();
|
||||
let argv = args.as_ptr();
|
||||
unsafe {
|
||||
scope
|
||||
.cast_local(|_| v8__Function__Call(self, &*context, &*recv, argc, argv))
|
||||
scope.cast_local(|sd| {
|
||||
v8__Function__Call(self, sd.get_current_context(), &*recv, argc, argv)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
13
src/json.rs
13
src/json.rs
|
@ -21,18 +21,23 @@ extern "C" {
|
|||
/// successful.
|
||||
pub fn parse<'s>(
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<'_, Context>,
|
||||
json_string: Local<'_, String>,
|
||||
) -> Option<Local<'s, Value>> {
|
||||
unsafe { scope.cast_local(|_| v8__JSON__Parse(&*context, &*json_string)) }
|
||||
unsafe {
|
||||
scope
|
||||
.cast_local(|sd| v8__JSON__Parse(sd.get_current_context(), &*json_string))
|
||||
}
|
||||
}
|
||||
|
||||
/// Tries to stringify the JSON-serializable object `json_object` and returns
|
||||
/// it as string if successful.
|
||||
pub fn stringify<'s>(
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<'s, Context>,
|
||||
json_object: Local<'s, Value>,
|
||||
) -> Option<Local<'s, String>> {
|
||||
unsafe { scope.cast_local(|_| v8__JSON__Stringify(&*context, &*json_object)) }
|
||||
unsafe {
|
||||
scope.cast_local(|sd| {
|
||||
v8__JSON__Stringify(sd.get_current_context(), &*json_object)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
//! let code = v8::String::new(scope, "'Hello' + ' World!'").unwrap();
|
||||
//! println!("javascript code: {}", code.to_rust_string_lossy(scope));
|
||||
//!
|
||||
//! let mut script = v8::Script::compile(scope, context, code, None).unwrap();
|
||||
//! let result = script.run(scope, context).unwrap();
|
||||
//! let mut script = v8::Script::compile(scope, code, None).unwrap();
|
||||
//! let result = script.run(scope).unwrap();
|
||||
//! let result = result.to_string(scope).unwrap();
|
||||
//! println!("result: {}", result.to_rust_string_lossy(scope));
|
||||
//! ```
|
||||
|
|
|
@ -205,11 +205,15 @@ impl Module {
|
|||
#[must_use]
|
||||
pub fn instantiate_module<'a>(
|
||||
&mut self,
|
||||
context: Local<Context>,
|
||||
scope: &mut HandleScope,
|
||||
callback: impl MapFnTo<ResolveCallback<'a>>,
|
||||
) -> Option<bool> {
|
||||
unsafe {
|
||||
v8__Module__InstantiateModule(self, &*context, callback.map_fn_to())
|
||||
v8__Module__InstantiateModule(
|
||||
self,
|
||||
&*scope.get_current_context(),
|
||||
callback.map_fn_to(),
|
||||
)
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
@ -224,8 +228,10 @@ impl Module {
|
|||
pub fn evaluate<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'s, Value>> {
|
||||
unsafe { scope.cast_local(|_| v8__Module__Evaluate(&*self, &*context)) }
|
||||
unsafe {
|
||||
scope
|
||||
.cast_local(|sd| v8__Module__Evaluate(&*self, sd.get_current_context()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,32 +130,41 @@ impl Object {
|
|||
/// result.Check().
|
||||
pub fn set(
|
||||
&self,
|
||||
context: Local<Context>,
|
||||
scope: &mut HandleScope,
|
||||
key: Local<Value>,
|
||||
value: Local<Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Object__Set(self, &*context, &*key, &*value) }.into()
|
||||
unsafe {
|
||||
v8__Object__Set(self, &*scope.get_current_context(), &*key, &*value)
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Set only return Just(true) or Empty(), so if it should never fail, use
|
||||
/// result.Check().
|
||||
pub fn set_index(
|
||||
&self,
|
||||
context: Local<Context>,
|
||||
scope: &mut HandleScope,
|
||||
index: u32,
|
||||
value: Local<Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Object__SetIndex(self, &*context, index, &*value) }.into()
|
||||
unsafe {
|
||||
v8__Object__SetIndex(self, &*scope.get_current_context(), index, &*value)
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Set the prototype object. This does not skip objects marked to be
|
||||
/// skipped by proto and it does not consult the security handler.
|
||||
pub fn set_prototype(
|
||||
&self,
|
||||
context: Local<Context>,
|
||||
scope: &mut HandleScope,
|
||||
prototype: Local<Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Object__SetPrototype(self, &*context, &*prototype) }.into()
|
||||
unsafe {
|
||||
v8__Object__SetPrototype(self, &*scope.get_current_context(), &*prototype)
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Implements CreateDataProperty (ECMA-262, 7.3.4).
|
||||
|
@ -167,12 +176,19 @@ impl Object {
|
|||
/// Returns true on success.
|
||||
pub fn create_data_property(
|
||||
&self,
|
||||
context: Local<Context>,
|
||||
scope: &mut HandleScope,
|
||||
key: Local<Name>,
|
||||
value: Local<Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Object__CreateDataProperty(self, &*context, &*key, &*value) }
|
||||
.into()
|
||||
unsafe {
|
||||
v8__Object__CreateDataProperty(
|
||||
self,
|
||||
&*scope.get_current_context(),
|
||||
&*key,
|
||||
&*value,
|
||||
)
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Implements DefineOwnProperty.
|
||||
|
@ -183,13 +199,19 @@ impl Object {
|
|||
/// Returns true on success.
|
||||
pub fn define_own_property(
|
||||
&self,
|
||||
context: Local<Context>,
|
||||
scope: &mut HandleScope,
|
||||
key: Local<Name>,
|
||||
value: Local<Value>,
|
||||
attr: PropertyAttribute,
|
||||
) -> Option<bool> {
|
||||
unsafe {
|
||||
v8__Object__DefineOwnProperty(self, &*context, &*key, &*value, attr)
|
||||
v8__Object__DefineOwnProperty(
|
||||
self,
|
||||
&*scope.get_current_context(),
|
||||
&*key,
|
||||
&*value,
|
||||
attr,
|
||||
)
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
@ -197,20 +219,23 @@ impl Object {
|
|||
pub fn get<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
key: Local<Value>,
|
||||
) -> Option<Local<'s, Value>> {
|
||||
unsafe { scope.cast_local(|_| v8__Object__Get(self, &*context, &*key)) }
|
||||
unsafe {
|
||||
scope
|
||||
.cast_local(|sd| v8__Object__Get(self, sd.get_current_context(), &*key))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_index<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
index: u32,
|
||||
) -> Option<Local<'s, Value>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| v8__Object__GetIndex(self, &*context, index))
|
||||
scope.cast_local(|sd| {
|
||||
v8__Object__GetIndex(self, sd.get_current_context(), index)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,12 +251,17 @@ impl Object {
|
|||
/// Note: SideEffectType affects the getter only, not the setter.
|
||||
pub fn set_accessor(
|
||||
&mut self,
|
||||
context: Local<Context>,
|
||||
scope: &mut HandleScope,
|
||||
name: Local<Name>,
|
||||
getter: impl for<'s> MapFnTo<AccessorNameGetterCallback<'s>>,
|
||||
) -> Option<bool> {
|
||||
unsafe {
|
||||
v8__Object__SetAccessor(self, &*context, &*name, getter.map_fn_to())
|
||||
v8__Object__SetAccessor(
|
||||
self,
|
||||
&*scope.get_current_context(),
|
||||
&*name,
|
||||
getter.map_fn_to(),
|
||||
)
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
@ -259,10 +289,11 @@ impl Object {
|
|||
pub fn get_own_property_names<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'s, Array>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| v8__Object__GetOwnPropertyNames(self, &*context))
|
||||
scope.cast_local(|sd| {
|
||||
v8__Object__GetOwnPropertyNames(self, sd.get_current_context())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,10 +304,11 @@ impl Object {
|
|||
pub fn get_property_names<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'s, Array>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| v8__Object__GetPropertyNames(self, &*context))
|
||||
scope.cast_local(|sd| {
|
||||
v8__Object__GetPropertyNames(self, sd.get_current_context())
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,11 +89,12 @@ impl Promise {
|
|||
pub fn catch<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
handler: Local<Function>,
|
||||
) -> Option<Local<'s, Promise>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| v8__Promise__Catch(&*self, &*context, &*handler))
|
||||
scope.cast_local(|sd| {
|
||||
v8__Promise__Catch(&*self, sd.get_current_context(), &*handler)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,11 +104,12 @@ impl Promise {
|
|||
pub fn then<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
handler: Local<Function>,
|
||||
) -> Option<Local<'s, Promise>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| v8__Promise__Then(&*self, &*context, &*handler))
|
||||
scope.cast_local(|sd| {
|
||||
v8__Promise__Then(&*self, sd.get_current_context(), &*handler)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,13 +120,17 @@ impl Promise {
|
|||
pub fn then2<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
on_fulfilled: Local<Function>,
|
||||
on_rejected: Local<Function>,
|
||||
) -> Option<Local<'s, Promise>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| {
|
||||
v8__Promise__Then2(&*self, &*context, &*on_fulfilled, &*on_rejected)
|
||||
scope.cast_local(|sd| {
|
||||
v8__Promise__Then2(
|
||||
&*self,
|
||||
sd.get_current_context(),
|
||||
&*on_fulfilled,
|
||||
&*on_rejected,
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -134,9 +140,11 @@ impl PromiseResolver {
|
|||
/// Create a new resolver, along with an associated promise in pending state.
|
||||
pub fn new<'s>(
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<'s, Context>,
|
||||
) -> Option<Local<'s, PromiseResolver>> {
|
||||
unsafe { scope.cast_local(|_| v8__Promise__Resolver__New(&*context)) }
|
||||
unsafe {
|
||||
scope
|
||||
.cast_local(|sd| v8__Promise__Resolver__New(sd.get_current_context()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract the associated promise.
|
||||
|
@ -150,22 +158,36 @@ impl PromiseResolver {
|
|||
|
||||
/// Resolve the associated promise with a given value.
|
||||
/// Ignored if the promise is no longer pending.
|
||||
pub fn resolve<'s>(
|
||||
pub fn resolve(
|
||||
&self,
|
||||
context: Local<'s, Context>,
|
||||
value: Local<'s, Value>,
|
||||
scope: &mut HandleScope,
|
||||
value: Local<'_, Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Promise__Resolver__Resolve(&*self, &*context, &*value).into() }
|
||||
unsafe {
|
||||
v8__Promise__Resolver__Resolve(
|
||||
&*self,
|
||||
&*scope.get_current_context(),
|
||||
&*value,
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Reject the associated promise with a given value.
|
||||
/// Ignored if the promise is no longer pending.
|
||||
pub fn reject<'s>(
|
||||
pub fn reject(
|
||||
&self,
|
||||
context: Local<'s, Context>,
|
||||
value: Local<'s, Value>,
|
||||
scope: &mut HandleScope,
|
||||
value: Local<'_, Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Promise__Resolver__Reject(&*self, &*context, &*value).into() }
|
||||
unsafe {
|
||||
v8__Promise__Resolver__Reject(
|
||||
&*self,
|
||||
&*scope.get_current_context(),
|
||||
&*value,
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,13 @@ extern "C" {
|
|||
impl Proxy {
|
||||
pub fn new<'s>(
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
target: Local<Object>,
|
||||
handler: Local<Object>,
|
||||
) -> Option<Local<'s, Proxy>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| v8__Proxy__New(&*context, &*target, &*handler))
|
||||
scope.cast_local(|sd| {
|
||||
v8__Proxy__New(sd.get_current_context(), &*target, &*handler)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,14 +44,13 @@ impl Script {
|
|||
/// A shorthand for ScriptCompiler::Compile().
|
||||
pub fn compile<'s>(
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
source: Local<String>,
|
||||
origin: Option<&ScriptOrigin>,
|
||||
) -> Option<Local<'s, Script>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| {
|
||||
scope.cast_local(|sd| {
|
||||
v8__Script__Compile(
|
||||
&*context,
|
||||
sd.get_current_context(),
|
||||
&*source,
|
||||
origin.map(|r| r as *const _).unwrap_or_else(null),
|
||||
)
|
||||
|
@ -65,9 +64,10 @@ impl Script {
|
|||
pub fn run<'s>(
|
||||
&mut self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'s, Value>> {
|
||||
unsafe { scope.cast_local(|_| v8__Script__Run(self, &*context)) }
|
||||
unsafe {
|
||||
scope.cast_local(|sd| v8__Script__Run(self, sd.get_current_context()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,11 +81,12 @@ impl FunctionTemplate {
|
|||
/// Returns the unique function instance in the current execution context.
|
||||
pub fn get_function<'s>(
|
||||
&mut self,
|
||||
scope: &mut HandleScope<'s, ()>,
|
||||
context: Local<Context>,
|
||||
scope: &mut HandleScope<'s>,
|
||||
) -> Option<Local<'s, Function>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| v8__FunctionTemplate__GetFunction(&*self, &*context))
|
||||
scope.cast_local(|sd| {
|
||||
v8__FunctionTemplate__GetFunction(&*self, sd.get_current_context())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,10 +125,11 @@ impl ObjectTemplate {
|
|||
pub fn new_instance<'s>(
|
||||
&self,
|
||||
scope: &mut HandleScope<'s>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'s, Object>> {
|
||||
unsafe {
|
||||
scope.cast_local(|_| v8__ObjectTemplate__NewInstance(self, &*context))
|
||||
scope.cast_local(|sd| {
|
||||
v8__ObjectTemplate__NewInstance(self, sd.get_current_context())
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ impl CoreIsolate {
|
|||
let context = v8::Context::new(scope);
|
||||
let scope = &mut v8::ContextScope::new(scope, context);
|
||||
let source = v8::String::new(scope, code).unwrap();
|
||||
let mut script = v8::Script::compile(scope, context, source, None).unwrap();
|
||||
let r = script.run(scope, context);
|
||||
let mut script = v8::Script::compile(scope, source, None).unwrap();
|
||||
let r = script.run(scope);
|
||||
r.is_some()
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue