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

Function FindWrapper

Dependencies/napi/source/js_native_api_chakra.cc:233–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233inline napi_status FindWrapper(napi_env env, JsValueRef obj, JsValueRef* wrapper, JsValueRef* parent = nullptr) {
234 // Search the object's prototype chain for the wrapper with external data.
235 // Usually the wrapper would be the first in the chain, but it is OK for
236 // other objects to be inserted in the prototype chain.
237 JsValueRef candidate = obj;
238 JsValueRef current = JS_INVALID_REFERENCE;
239 bool hasExternalData = false;
240
241 JsValueRef nullValue = JS_INVALID_REFERENCE;
242 CHECK_JSRT(env, JsGetNullValue(&nullValue));
243
244 do {
245 current = candidate;
246
247 CHECK_JSRT(env, JsGetPrototype(current, &candidate));
248 if (candidate == JS_INVALID_REFERENCE || candidate == nullValue) {
249 if (parent != nullptr) {
250 *parent = JS_INVALID_REFERENCE;
251 }
252
253 *wrapper = JS_INVALID_REFERENCE;
254 return napi_ok;
255 }
256
257 CHECK_JSRT(env, JsHasExternalData(candidate, &hasExternalData));
258 } while (!hasExternalData);
259
260 if (parent != nullptr) {
261 *parent = current;
262 }
263
264 *wrapper = candidate;
265
266 return napi_ok;
267}
268
269inline napi_status Unwrap(napi_env env, JsValueRef obj, ExternalData** externalData, JsValueRef* wrapper = nullptr, JsValueRef* parent = nullptr) {
270 JsValueRef candidate = JS_INVALID_REFERENCE;

Callers 2

UnwrapFunction · 0.85
napi_wrapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected