2020-01-02 13:57:00 -05:00
|
|
|
// Copyright 2019-2020 the Deno authors. All rights reserved. MIT license.
|
2019-12-21 06:38:26 -05:00
|
|
|
use crate::Local;
|
|
|
|
use crate::PrimitiveArray;
|
2020-03-05 17:41:43 -08:00
|
|
|
use crate::ScriptOrModule;
|
2019-12-21 06:38:26 -05:00
|
|
|
use crate::Value;
|
|
|
|
|
|
|
|
extern "C" {
|
2020-04-13 14:43:56 +02:00
|
|
|
fn v8__ScriptOrModule__GetResourceName(
|
|
|
|
this: *const ScriptOrModule,
|
|
|
|
) -> *const Value;
|
2019-12-21 06:38:26 -05:00
|
|
|
|
|
|
|
fn v8__ScriptOrModule__GetHostDefinedOptions(
|
2020-04-13 14:43:56 +02:00
|
|
|
this: *const ScriptOrModule,
|
|
|
|
) -> *const PrimitiveArray;
|
2019-12-21 06:38:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ScriptOrModule {
|
|
|
|
/// The name that was passed by the embedder as ResourceName to the
|
|
|
|
/// ScriptOrigin. This can be either a v8::String or v8::Undefined.
|
2020-05-31 18:45:00 +02:00
|
|
|
pub fn get_resource_name(&self) -> Local<Value> {
|
2020-05-31 19:22:08 +02:00
|
|
|
// Note: the C++ `v8::ScriptOrModule::GetResourceName()` does not actually
|
|
|
|
// return a local handle, but rather a handle whose lifetime is bound to
|
|
|
|
// the related `ScriptOrModule` object.
|
2019-12-21 06:38:26 -05:00
|
|
|
unsafe {
|
|
|
|
let ptr = v8__ScriptOrModule__GetResourceName(self);
|
2019-12-25 12:39:42 +01:00
|
|
|
Local::from_raw(ptr).unwrap()
|
2019-12-21 06:38:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The options that were passed by the embedder as HostDefinedOptions to the
|
|
|
|
/// ScriptOrigin.
|
2020-05-31 18:45:00 +02:00
|
|
|
pub fn get_host_defined_options(&self) -> Local<PrimitiveArray> {
|
2020-05-31 19:22:08 +02:00
|
|
|
// Note: the C++ `v8::ScriptOrModule::GetHostDefinedOptions()` does not
|
|
|
|
// actually return a local handle, but rather a handle whose lifetime is
|
|
|
|
// bound to the related `ScriptOrModule` object.
|
2019-12-21 06:38:26 -05:00
|
|
|
unsafe {
|
|
|
|
let ptr = v8__ScriptOrModule__GetHostDefinedOptions(self);
|
2019-12-25 12:39:42 +01:00
|
|
|
Local::from_raw(ptr).unwrap()
|
2019-12-21 06:38:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|