@@ -317,30 +317,43 @@ namespace Js
317
317
{
318
318
EngineInterfaceObject_CommonFunctionProlog (function, callInfo);
319
319
320
- if (callInfo.Count >= 2 && JavascriptFunction::Is (args.Values [1 ]))
320
+ AssertOrFailFast ((callInfo.Count == 3 || callInfo.Count == 4 ) && JavascriptFunction::Is (args[1 ]) && JavascriptString::Is (args[2 ]));
321
+
322
+ JavascriptFunction *func = JavascriptFunction::UnsafeFromVar (args[1 ]);
323
+ JavascriptString *methodName = JavascriptString::UnsafeFromVar (args[2 ]);
324
+
325
+ func->GetFunctionProxy ()->SetIsPublicLibraryCode ();
326
+
327
+ // use GetSz rather than GetString because we use wcsrchr below, which expects a null-terminated string
328
+ const char16 *methodNameBuf = methodName->GetSz ();
329
+ charcount_t methodNameLength = methodName->GetLength ();
330
+ const char16 *shortName = wcsrchr (methodNameBuf, _u (' .' ));
331
+ charcount_t shortNameOffset = 0 ;
332
+ if (shortName != nullptr )
321
333
{
322
- JavascriptFunction* func = JavascriptFunction::FromVar (args.Values [1 ]);
323
- func->GetFunctionProxy ()->SetIsPublicLibraryCode ();
334
+ shortName++;
335
+ shortNameOffset = static_cast <charcount_t >(shortName - methodNameBuf);
336
+ }
324
337
325
- if (callInfo.Count >= 3 && JavascriptString::Is (args.Values [2 ]))
326
- {
327
- JavascriptString* customFunctionName = JavascriptString::FromVar (args.Values [2 ]);
328
- // tagPublicFunction("Intl.Collator", Collator); in Intl.js calls TagPublicLibraryCode the expected name is Collator so we need to calculate the offset
329
- const char16 * shortName = wcsrchr (customFunctionName->GetString (), _u (' .' ));
330
- uint shortNameOffset = 0 ;
331
- if (shortName != nullptr )
332
- {
333
- // JavascriptString length is bounded by uint max
334
- shortName++;
335
- shortNameOffset = static_cast <uint>(shortName - customFunctionName->GetString ());
336
- }
337
- func->GetFunctionProxy ()->EnsureDeserialized ()->SetDisplayName (customFunctionName->GetString (), customFunctionName->GetLength (), shortNameOffset);
338
- }
338
+ func->GetFunctionProxy ()->EnsureDeserialized ()->SetDisplayName (methodNameBuf, methodNameLength, shortNameOffset);
339
339
340
- return func;
340
+ bool creatingConstructor = true ;
341
+ if (callInfo.Count == 4 )
342
+ {
343
+ AssertOrFailFast (JavascriptBoolean::Is (args[3 ]));
344
+ creatingConstructor = JavascriptBoolean::UnsafeFromVar (args[3 ])->GetValue ();
341
345
}
342
346
343
- return scriptContext->GetLibrary ()->GetUndefined ();
347
+ if (!creatingConstructor)
348
+ {
349
+ FunctionInfo *info = func->GetFunctionInfo ();
350
+ info->SetAttributes ((FunctionInfo::Attributes) (info->GetAttributes () | FunctionInfo::Attributes::ErrorOnNew));
351
+
352
+ AssertOrFailFast (func->GetDynamicType ()->GetTypeHandler ()->IsDeferredTypeHandler ());
353
+ DynamicTypeHandler::SetInstanceTypeHandler (func, scriptContext->GetLibrary ()->GetDeferredFunctionWithLengthTypeHandler ());
354
+ }
355
+
356
+ return func;
344
357
}
345
358
346
359
/*
0 commit comments