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

Function SetErrorCode

Dependencies/napi/source/js_native_api_chakra.cc:289–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287}
288
289static napi_status SetErrorCode(napi_env env, JsValueRef error, napi_value code, const char* codeString) {
290 if ((code != nullptr) || (codeString != nullptr)) {
291 JsValueRef codeValue = reinterpret_cast<JsValueRef>(code);
292 if (codeValue != JS_INVALID_REFERENCE) {
293 JsValueType valueType = JsUndefined;
294 CHECK_JSRT(env, JsGetValueType(codeValue, &valueType));
295 RETURN_STATUS_IF_FALSE(env, valueType == JsString, napi_string_expected);
296 } else {
297 CHECK_JSRT(env, JsCreateString(codeString, NAPI_AUTO_LENGTH, &codeValue));
298 }
299
300 JsPropertyIdRef codePropId = JS_INVALID_REFERENCE;
301 CHECK_JSRT(env, JsCreatePropertyId(STR_AND_LENGTH("code"), &codePropId));
302
303 CHECK_JSRT(env, JsSetProperty(error, codePropId, codeValue, true));
304
305 JsValueRef nameArray = JS_INVALID_REFERENCE;
306 CHECK_JSRT(env, JsCreateArray(0, &nameArray));
307
308 JsPropertyIdRef pushPropId = JS_INVALID_REFERENCE;
309 CHECK_JSRT(env, JsCreatePropertyId(STR_AND_LENGTH("push"), &pushPropId));
310
311 JsValueRef pushFunction = JS_INVALID_REFERENCE;
312 CHECK_JSRT(env, JsGetProperty(nameArray, pushPropId, &pushFunction));
313
314 JsPropertyIdRef namePropId = JS_INVALID_REFERENCE;
315 CHECK_JSRT(env, JsCreatePropertyId(STR_AND_LENGTH("name"), &namePropId));
316
317 bool hasProp = false;
318 CHECK_JSRT(env, JsHasProperty(error, namePropId, &hasProp));
319
320 JsValueRef nameValue = JS_INVALID_REFERENCE;
321 std::array<JsValueRef, 2> args = { nameArray, JS_INVALID_REFERENCE };
322
323 if (hasProp) {
324 CHECK_JSRT(env, JsGetProperty(error, namePropId, &nameValue));
325
326 args[1] = nameValue;
327 CHECK_JSRT(env,
328 JsCallFunction(pushFunction,
329 args.data(),
330 static_cast<unsigned short>(args.size()),
331 nullptr));
332 }
333
334 const char* openBracket = " [";
335 JsValueRef openBracketValue = JS_INVALID_REFERENCE;
336 CHECK_JSRT(env, JsCreateString(openBracket, NAPI_AUTO_LENGTH, &openBracketValue));
337
338 args[1] = openBracketValue;
339 CHECK_JSRT(env, JsCallFunction(pushFunction, args.data(), static_cast<unsigned short>(args.size()), nullptr));
340
341 args[1] = codeValue;
342 CHECK_JSRT(env, JsCallFunction(pushFunction, args.data(), static_cast<unsigned short>(args.size()), nullptr));
343
344 const char* closeBracket = "]";
345 JsValueRef closeBracketValue = JS_INVALID_REFERENCE;
346 CHECK_JSRT(env, JsCreateString(closeBracket, NAPI_AUTO_LENGTH, &closeBracketValue));

Callers 6

napi_create_errorFunction · 0.85
napi_create_type_errorFunction · 0.85
napi_create_range_errorFunction · 0.85
napi_throw_errorFunction · 0.85
napi_throw_type_errorFunction · 0.85
napi_throw_range_errorFunction · 0.85

Calls 2

JsCreateStringFunction · 0.85
JsCreatePropertyIdFunction · 0.85

Tested by

no test coverage detected