| 352 | } |
| 353 | |
| 354 | StringBox nameFromJSFunction(IJavaScriptContext& jsContext, const JSValue& jsValue) { |
| 355 | static auto kNameKey = STRING_LITERAL("name"); |
| 356 | static auto kAnonymousFunction = STRING_LITERAL("<anon>"); |
| 357 | static auto kAnonymousBoundFunction = STRING_LITERAL("bound <anon>"); |
| 358 | static auto kNameWhenBoundAnonymous = STRING_LITERAL("bound "); |
| 359 | |
| 360 | JSExceptionTracker exceptionTracker(jsContext); |
| 361 | auto name = jsContext.getObjectProperty(jsValue, jsContext.getPropertyNameCached(kNameKey), exceptionTracker); |
| 362 | if (!exceptionTracker || jsContext.isValueUndefined(name.get())) { |
| 363 | exceptionTracker.clearError(); |
| 364 | return kAnonymousFunction; |
| 365 | } |
| 366 | |
| 367 | auto str = jsContext.valueToString(name.get(), exceptionTracker); |
| 368 | if (!exceptionTracker) { |
| 369 | exceptionTracker.clearError(); |
| 370 | return kAnonymousFunction; |
| 371 | } |
| 372 | |
| 373 | if (str.isEmpty()) { |
| 374 | // In JS empty string means name no set |
| 375 | return kAnonymousFunction; |
| 376 | } |
| 377 | |
| 378 | if (str == kNameWhenBoundAnonymous) { |
| 379 | return kAnonymousBoundFunction; |
| 380 | } |
| 381 | |
| 382 | return str; |
| 383 | } |
| 384 | |
| 385 | static bool checkRefNotCircular(const JSValue& value, |
| 386 | JavaScriptCircularRefChecker<JSValue>& circularRefChecker, |
no test coverage detected