MCPcopy Create free account
hub / github.com/BabylonJS/BabylonNative / Initialize

Method Initialize

Polyfills/Window/Source/Window.cpp:16–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14 }
15
16 void Window::Initialize(Napi::Env env)
17 {
18 Napi::HandleScope scope{env};
19
20 Napi::Function constructor = DefineClass(
21 env,
22 JS_CLASS_NAME,
23 {});
24
25 auto global = env.Global();
26 auto jsNative = global.Get(JsRuntime::JS_NATIVE_NAME).As<Napi::Object>();
27 auto jsWindow = constructor.New({});
28
29 // Need a reference or It's destroyed when loading babylon.material.js
30 // TODO: Find why
31 napi_ref result;
32 napi_create_reference(env, jsWindow, 1, &result);
33
34 jsNative.Set(JS_WINDOW_NAME, jsWindow);
35
36 if (global.Get(JS_SET_TIMEOUT_NAME).IsUndefined())
37 {
38 global.Set(JS_SET_TIMEOUT_NAME, Napi::Function::New(env, &Window::SetTimeout, JS_SET_TIMEOUT_NAME, Window::Unwrap(jsWindow)));
39 }
40
41 if (global.Get(JS_A_TO_B_NAME).IsUndefined())
42 {
43 global.Set(JS_A_TO_B_NAME, Napi::Function::New(env, &Window::DecodeBase64, JS_A_TO_B_NAME));
44 }
45
46 if (global.Get(JS_ADD_EVENT_LISTENER_NAME).IsUndefined())
47 {
48 global.Set(JS_ADD_EVENT_LISTENER_NAME, Napi::Function::New(env, &Window::AddEventListener, JS_ADD_EVENT_LISTENER_NAME));
49 }
50
51 if (global.Get(JS_REMOVE_EVENT_LISTENER_NAME).IsUndefined())
52 {
53 global.Set(JS_REMOVE_EVENT_LISTENER_NAME, Napi::Function::New(env, &Window::RemoveEventListener, JS_REMOVE_EVENT_LISTENER_NAME));
54 }
55 }
56
57 Window& Window::GetFromJavaScript(Napi::Env env)
58 {

Callers

nothing calls this directly

Calls 7

GlobalMethod · 0.80
SetMethod · 0.80
IsUndefinedMethod · 0.80
napi_create_referenceFunction · 0.50
UnwrapFunction · 0.50
GetMethod · 0.45
NewMethod · 0.45

Tested by

no test coverage detected