| 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 | { |
nothing calls this directly
no test coverage detected