pub fn new(mut options: RuntimeOptions) -> Self {
    let v8_platform = options.v8_platform.take();

    static DENO_INIT: Once = Once::new();
    DENO_INIT.call_once(move || v8_init(v8_platform));

    let has_startup_snapshot = options.startup_snapshot.is_some();

    let global_context;
    let (mut isolate, maybe_snapshot_creator) = if options.will_snapshot {
      // TODO(ry) Support loading snapshots before snapshotting.
      assert!(options.startup_snapshot.is_none());
      let mut creator =
        v8::SnapshotCreator::new(Some(&bindings::EXTERNAL_REFERENCES));
      let isolate = unsafe { creator.get_owned_isolate() };
      let mut isolate = JsRuntime::setup_isolate(isolate);
      {
        let scope = &mut v8::HandleScope::new(&mut isolate);
        let context = bindings::initialize_context(scope);
        global_context = v8::Global::new(scope, context);
        creator.set_default_context(context);
      }
      (isolate, Some(creator))
    } else {
      let mut params = options
        .create_params
        .take()
        .unwrap_or_else(v8::Isolate::create_params)
        .external_references(&**bindings::EXTERNAL_REFERENCES);
      let snapshot_loaded = if let Some(snapshot) = options.startup_snapshot {
        params = match snapshot {
          Snapshot::Static(data) => params.snapshot_blob(data),
          Snapshot::JustCreated(data) => params.snapshot_blob(data),
          Snapshot::Boxed(data) => params.snapshot_blob(data),
        };
        true
      } else {
        false
      };

      let isolate = v8::Isolate::new(params);
      let mut isolate = JsRuntime::setup_isolate(isolate);
      {
        let scope = &mut v8::HandleScope::new(&mut isolate);
        let context = if snapshot_loaded {
          v8::Context::new(scope)
        } else {
          // If no snapshot is provided, we initialize the context with empty
          // main source code and source maps.
          bindings::initialize_context(scope)
        };
        global_context = v8::Global::new(scope, context);
      }
      (isolate, None)
    };

    let inspector =
      JsRuntimeInspector::new(&mut isolate, global_context.clone());

    let loader = options
      .module_loader
      .unwrap_or_else(|| Rc::new(NoopModuleLoader));

    let js_error_create_fn = options
      .js_error_create_fn
      .unwrap_or_else(|| Rc::new(JsError::create));
    let mut op_state = OpState::new();

    if let Some(get_error_class_fn) = options.get_error_class_fn {
      op_state.get_error_class_fn = get_error_class_fn;
    }

    let op_state = Rc::new(RefCell::new(op_state));

    isolate.set_slot(Rc::new(RefCell::new(JsRuntimeState {
      global_context: Some(global_context),
      pending_promise_exceptions: HashMap::new(),
      pending_dyn_mod_evaluate: VecDeque::new(),
      pending_mod_evaluate: None,
      js_recv_cb: None,
      js_macrotask_cb: None,
      js_error_create_fn,
      pending_ops: FuturesUnordered::new(),
      pending_unref_ops: FuturesUnordered::new(),
      op_state: op_state.clone(),
      have_unpolled_ops: false,
      waker: AtomicWaker::new(),
    })));

    let module_map = ModuleMap::new(loader, op_state);
    isolate.set_slot(Rc::new(RefCell::new(module_map)));

    // Add builtins extension
    options
      .extensions
      .insert(0, crate::ops_builtin::init_builtins());

    let mut js_runtime = Self {
      v8_isolate: Some(isolate),
      inspector: Some(inspector),
      snapshot_creator: maybe_snapshot_creator,
      has_snapshotted: false,
      allocations: IsolateAllocations::default(),
      extensions: options.extensions,
    };

    // TODO(@AaronO): diff extensions inited in snapshot and those provided
    // for now we assume that snapshot and extensions always match
    if !has_startup_snapshot {
      js_runtime.init_extension_js().unwrap();
    }
    // Init extension ops
    js_runtime.init_extension_ops().unwrap();
    js_runtime.sync_ops_cache();
    // Init async ops callback
    js_runtime.init_recv_cb();

    js_runtime
  }
/// Only constructor, configuration is done through `options`.
Only constructor, configuration is done through `options`.
Only constructor configuration is done through ` options ` .
pub fn new(mut options: RuntimeOptions) -> Self {
    let v8_platform = options.v8_platform.take();
    static DENO_INIT: Once = Once::new();
    DENO_INIT.call_once(move || v8_init(v8_platform));
    let has_startup_snapshot = options.startup_snapshot.is_some();
    let global_context;
    let (mut isolate, maybe_snapshot_creator) = if options.will_snapshot {
      // TODO(ry) Support loading snapshots before snapshotting.
      assert!(options.startup_snapshot.is_none());
      let mut creator =
        v8::SnapshotCreator::new(Some(&bindings::EXTERNAL_REFERENCES));
      let isolate = unsafe { creator.get_owned_isolate() };
      let mut isolate = JsRuntime::setup_isolate(isolate);
      {
        let scope = &mut v8::HandleScope::new(&mut isolate);
        let context = bindings::initialize_context(scope);
        global_context = v8::Global::new(scope, context);
        creator.set_default_context(context);
      }
      (isolate, Some(creator))
    } else {
      let mut params = options
        .create_params
        .take()
        .unwrap_or_else(v8::Isolate::create_params)
        .external_references(&**bindings::EXTERNAL_REFERENCES);
      let snapshot_loaded = if let Some(snapshot) = options.startup_snapshot {
        params = match snapshot {
          Snapshot::Static(data) => params.snapshot_blob(data),
          Snapshot::JustCreated(data) => params.snapshot_blob(data),
          Snapshot::Boxed(data) => params.snapshot_blob(data),
        };
        true
      } else {
        false
      };
      let isolate = v8::Isolate::new(params);
      let mut isolate = JsRuntime::setup_isolate(isolate);
      {
        let scope = &mut v8::HandleScope::new(&mut isolate);
        let context = if snapshot_loaded {
          v8::Context::new(scope)
        } else {
          // If no snapshot is provided, we initialize the context with empty
          // main source code and source maps.
          bindings::initialize_context(scope)
        };
        global_context = v8::Global::new(scope, context);
      }
      (isolate, None)
    };
    let inspector =
      JsRuntimeInspector::new(&mut isolate, global_context.clone());
    let loader = options
      .module_loader
      .unwrap_or_else(|| Rc::new(NoopModuleLoader));
    let js_error_create_fn = options
      .js_error_create_fn
      .unwrap_or_else(|| Rc::new(JsError::create));
    let mut op_state = OpState::new();
    if let Some(get_error_class_fn) = options.get_error_class_fn {
      op_state.get_error_class_fn = get_error_class_fn;
    }
    let op_state = Rc::new(RefCell::new(op_state));
    isolate.set_slot(Rc::new(RefCell::new(JsRuntimeState {
      global_context: Some(global_context),
      pending_promise_exceptions: HashMap::new(),
      pending_dyn_mod_evaluate: VecDeque::new(),
      pending_mod_evaluate: None,
      js_recv_cb: None,
      js_macrotask_cb: None,
      js_error_create_fn,
      pending_ops: FuturesUnordered::new(),
      pending_unref_ops: FuturesUnordered::new(),
      op_state: op_state.clone(),
      have_unpolled_ops: false,
      waker: AtomicWaker::new(),
    })));
    let module_map = ModuleMap::new(loader, op_state);
    isolate.set_slot(Rc::new(RefCell::new(module_map)));
    // Add builtins extension
    options
      .extensions
      .insert(0, crate::ops_builtin::init_builtins());
    let mut js_runtime = Self {
      v8_isolate: Some(isolate),
      inspector: Some(inspector),
      snapshot_creator: maybe_snapshot_creator,
      has_snapshotted: false,
      allocations: IsolateAllocations::default(),
      extensions: options.extensions,
    };
    // TODO(@AaronO): diff extensions inited in snapshot and those provided
    // for now we assume that snapshot and extensions always match
    if !has_startup_snapshot {
      js_runtime.init_extension_js().unwrap();
    }
    // Init extension ops
    js_runtime.init_extension_ops().unwrap();
    js_runtime.sync_ops_cache();
    // Init async ops callback
    js_runtime.init_recv_cb();
    js_runtime
  }
pub fn new ( mut options : RuntimeOptions ) -> Self { let v8_platform = options . v8_platform . take ( ) ; static DENO_INIT : Once = Once :: new ( ) ; DENO_INIT . call_once ( move | | v8_init ( v8_platform ) ) ; let has_startup_snapshot = options . startup_snapshot . is_some ( ) ; let global_context ; let ( mut isolate , maybe_snapshot_creator ) = if options . will_snapshot { // TODO(ry) Support loading snapshots before snapshotting. assert ! ( options startup_snapshot is_none ( ) ) ; let mut creator = v8 :: SnapshotCreator :: new ( Some ( & bindings :: EXTERNAL_REFERENCES ) ) ; let isolate = unsafe { creator . get_owned_isolate ( ) } ; let mut isolate = JsRuntime :: setup_isolate ( isolate ) ; { let scope = & mut v8 :: HandleScope :: new ( & mut isolate ) ; let context = bindings :: initialize_context ( scope ) ; global_context = v8 :: Global :: new ( scope , context ) ; creator . set_default_context ( context ) ; } ( isolate , Some ( creator ) ) } else { let mut params = options . create_params . take ( ) . unwrap_or_else ( v8 :: Isolate :: create_params ) . external_references ( & * * bindings :: EXTERNAL_REFERENCES ) ; let snapshot_loaded = if let Some ( snapshot ) = options . startup_snapshot { params = match snapshot { Snapshot :: Static ( data ) => params . snapshot_blob ( data ) , Snapshot :: JustCreated ( data ) => params . snapshot_blob ( data ) , Snapshot :: Boxed ( data ) => params . snapshot_blob ( data ) , } ; true } else { false } ; let isolate = v8 :: Isolate :: new ( params ) ; let mut isolate = JsRuntime :: setup_isolate ( isolate ) ; { let scope = & mut v8 :: HandleScope :: new ( & mut isolate ) ; let context = if snapshot_loaded { v8 :: Context :: new ( scope ) } else { // If no snapshot is provided, we initialize the context with empty // main source code and source maps. bindings :: initialize_context ( scope ) } ; global_context = v8 :: Global :: new ( scope , context ) ; } ( isolate , None ) } ; let inspector = JsRuntimeInspector :: new ( & mut isolate , global_context . clone ( ) ) ; let loader = options . module_loader . unwrap_or_else ( | | Rc :: new ( NoopModuleLoader ) ) ; let js_error_create_fn = options . js_error_create_fn . unwrap_or_else ( | | Rc :: new ( JsError :: create ) ) ; let mut op_state = OpState :: new ( ) ; if let Some ( get_error_class_fn ) = options . get_error_class_fn { op_state . get_error_class_fn = get_error_class_fn ; } let op_state = Rc :: new ( RefCell :: new ( op_state ) ) ; isolate . set_slot ( Rc :: new ( RefCell :: new ( JsRuntimeState { global_context : Some ( global_context ) , pending_promise_exceptions : HashMap :: new ( ) , pending_dyn_mod_evaluate : VecDeque :: new ( ) , pending_mod_evaluate : None , js_recv_cb : None , js_macrotask_cb : None , js_error_create_fn , pending_ops : FuturesUnordered :: new ( ) , pending_unref_ops : FuturesUnordered :: new ( ) , op_state : op_state . clone ( ) , have_unpolled_ops : false , waker : AtomicWaker :: new ( ) , } ) ) ) ; let module_map = ModuleMap :: new ( loader , op_state ) ; isolate . set_slot ( Rc :: new ( RefCell :: new ( module_map ) ) ) ; // Add builtins extension options . extensions . insert ( 0 , crate :: ops_builtin :: init_builtins ( ) ) ; let mut js_runtime = Self { v8_isolate : Some ( isolate ) , inspector : Some ( inspector ) , snapshot_creator : maybe_snapshot_creator , has_snapshotted : false , allocations : IsolateAllocations :: default ( ) , extensions : options . extensions , } ; // TODO(@AaronO): diff extensions inited in snapshot and those provided // for now we assume that snapshot and extensions always match if ! has_startup_snapshot { js_runtime . init_extension_js ( ) . unwrap ( ) ; } // Init extension ops js_runtime . init_extension_ops ( ) . unwrap ( ) ; js_runtime . sync_ops_cache ( ) ; // Init async ops callback js_runtime . init_recv_cb ( ) ; js_runtime }
Only constructor, configuration is done through `options`.
Only constructor configuration is done through ` options ` .
options
RuntimeOptions
options
RuntimeOptions