rusty_v8/
script_or_module.rs

1// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
2use crate::Local;
3use crate::PrimitiveArray;
4use crate::ScriptOrModule;
5use crate::Value;
6
7extern "C" {
8  fn v8__ScriptOrModule__GetResourceName(
9    this: *const ScriptOrModule,
10  ) -> *const Value;
11
12  fn v8__ScriptOrModule__GetHostDefinedOptions(
13    this: *const ScriptOrModule,
14  ) -> *const PrimitiveArray;
15}
16
17impl ScriptOrModule {
18  /// The name that was passed by the embedder as ResourceName to the
19  /// ScriptOrigin. This can be either a v8::String or v8::Undefined.
20  pub fn get_resource_name(&self) -> Local<Value> {
21    // Note: the C++ `v8::ScriptOrModule::GetResourceName()` does not actually
22    // return a local handle, but rather a handle whose lifetime is bound to
23    // the related `ScriptOrModule` object.
24    unsafe {
25      let ptr = v8__ScriptOrModule__GetResourceName(self);
26      Local::from_raw(ptr).unwrap()
27    }
28  }
29
30  /// The options that were passed by the embedder as HostDefinedOptions to the
31  /// ScriptOrigin.
32  pub fn get_host_defined_options(&self) -> Local<PrimitiveArray> {
33    // Note: the C++ `v8::ScriptOrModule::GetHostDefinedOptions()` does not
34    // actually return a local handle, but rather a handle whose lifetime is
35    // bound to the related `ScriptOrModule` object.
36    unsafe {
37      let ptr = v8__ScriptOrModule__GetHostDefinedOptions(self);
38      Local::from_raw(ptr).unwrap()
39    }
40  }
41}