Skip to content

Commit 3cd283f

Browse files
committed
Fix a number of test262 Intl issues
1 parent 067a87d commit 3cd283f

File tree

5 files changed

+302
-297
lines changed

5 files changed

+302
-297
lines changed

lib/Runtime/Library/EngineInterfaceObject.cpp

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -315,32 +315,48 @@ namespace Js
315315

316316
Var EngineInterfaceObject::Entry_TagPublicLibraryCode(RecyclableObject *function, CallInfo callInfo, ...)
317317
{
318+
#pragma warning(push)
319+
#pragma warning(suppress: 4189) // scriptContext is initialized by never used
318320
EngineInterfaceObject_CommonFunctionProlog(function, callInfo);
321+
#pragma warning(pop)
319322

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)
321336
{
322-
JavascriptFunction* func = JavascriptFunction::FromVar(args.Values[1]);
323-
func->GetFunctionProxy()->SetIsPublicLibraryCode();
337+
shortName++;
338+
shortNameOffset = static_cast<charcount_t>(shortName - methodNameBuf);
339+
}
324340

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);
339342

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();
341348
}
342349

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;
344360
}
345361

346362
/*

0 commit comments

Comments
 (0)