@@ -315,32 +315,48 @@ namespace Js
315
315
316
316
Var EngineInterfaceObject::Entry_TagPublicLibraryCode (RecyclableObject *function, CallInfo callInfo, ...)
317
317
{
318
+ #pragma warning(push)
319
+ #pragma warning(suppress: 4189) // scriptContext is initialized by never used
318
320
EngineInterfaceObject_CommonFunctionProlog (function, callInfo);
321
+ #pragma warning(pop)
319
322
320
- if (callInfo.Count >= 2 && JavascriptFunction::Is (args.Values [1 ]))
323
+ AssertOrFailFast ((callInfo.Count == 3 || callInfo.Count == 4 ) && JavascriptFunction::Is (args[1 ]) && JavascriptString::Is (args[2 ]));
324
+
325
+ JavascriptFunction *func = JavascriptFunction::UnsafeFromVar (args[1 ]);
326
+ JavascriptString *methodName = JavascriptString::UnsafeFromVar (args[2 ]);
327
+
328
+ func->GetFunctionProxy ()->SetIsPublicLibraryCode ();
329
+
330
+ // use GetSz rather than GetString because we use wcsrchr below, which expects a null-terminated string
331
+ const char16 *methodNameBuf = methodName->GetSz ();
332
+ charcount_t methodNameLength = methodName->GetLength ();
333
+ const char16 *shortName = wcsrchr (methodNameBuf, _u (' .' ));
334
+ charcount_t shortNameOffset = 0 ;
335
+ if (shortName != nullptr )
321
336
{
322
- JavascriptFunction* func = JavascriptFunction::FromVar (args.Values [1 ]);
323
- func->GetFunctionProxy ()->SetIsPublicLibraryCode ();
337
+ shortName++;
338
+ shortNameOffset = static_cast <charcount_t >(shortName - methodNameBuf);
339
+ }
324
340
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
- }
341
+ func->GetFunctionProxy ()->EnsureDeserialized ()->SetDisplayName (methodNameBuf, methodNameLength, shortNameOffset);
339
342
340
- return func;
343
+ bool creatingConstructor = true ;
344
+ if (callInfo.Count == 4 )
345
+ {
346
+ AssertOrFailFast (JavascriptBoolean::Is (args[3 ]));
347
+ creatingConstructor = JavascriptBoolean::UnsafeFromVar (args[3 ])->GetValue ();
341
348
}
342
349
343
- return scriptContext->GetLibrary ()->GetUndefined ();
350
+ if (!creatingConstructor)
351
+ {
352
+ FunctionInfo *info = func->GetFunctionInfo ();
353
+ info->SetAttributes ((FunctionInfo::Attributes) (info->GetAttributes () | FunctionInfo::Attributes::ErrorOnNew));
354
+
355
+ func->SetAttributes (PropertyIds::prototype, PropertyConfigurable);
356
+ func->DeleteProperty (PropertyIds::prototype, PropertyOperationFlags::PropertyOperation_Force);
357
+ }
358
+
359
+ return func;
344
360
}
345
361
346
362
/*
0 commit comments