Var JavascriptError::NewErrorInstance(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); JavascriptError* pError = scriptContext->GetLibrary()->CreateError(); // Process the arguments for IE specific behaviors for numbers and description JavascriptString* descriptionString = nullptr; bool hasNumber = false; double number = 0; if (args.Info.Count >= 3) { hasNumber = true; number = JavascriptConversion::ToNumber(args[1], scriptContext); // Get rid of this arg. NewInstance only expects a message arg. args.Values++; args.Info.Count--; descriptionString = JavascriptConversion::ToString(args[1], scriptContext); } else if (args.Info.Count == 2) { if (!hasNumber) { descriptionString = JavascriptConversion::ToString(args[1], scriptContext); } } else { hasNumber = true; descriptionString = scriptContext->GetLibrary()->GetEmptyString(); } Assert(descriptionString != nullptr); if (hasNumber) { JavascriptOperators::InitProperty(pError, PropertyIds::number, JavascriptNumber::ToVarNoCheck(number, scriptContext)); pError->SetNotEnumerable(PropertyIds::number); } JavascriptOperators::SetProperty(pError, pError, PropertyIds::description, descriptionString, scriptContext); pError->SetNotEnumerable(PropertyIds::description); return JavascriptError::NewInstance(function, pError, callInfo, args); }
Var JavascriptError::NewErrorInstance(RecyclableObject* function, CallInfo callInfo, ...) { PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault); ARGUMENTS(args, callInfo); ScriptContext* scriptContext = function->GetScriptContext(); JavascriptError* pError = scriptContext->GetLibrary()->CreateError(); // Process the arguments for IE specific behaviors for numbers and description JavascriptString* descriptionString = nullptr; Var message; bool hasNumber = false; double number = 0; if (args.Info.Count >= 3) { hasNumber = true; number = JavascriptConversion::ToNumber(args[1], scriptContext); message = args[2]; descriptionString = JavascriptConversion::ToString(message, scriptContext); } else if (args.Info.Count == 2) { message = args[1]; descriptionString = JavascriptConversion::ToString(message, scriptContext); } else { hasNumber = true; message = scriptContext->GetLibrary()->GetUndefined(); descriptionString = scriptContext->GetLibrary()->GetEmptyString(); } Assert(descriptionString != nullptr); if (hasNumber) { JavascriptOperators::InitProperty(pError, PropertyIds::number, JavascriptNumber::ToVarNoCheck(number, scriptContext)); pError->SetNotEnumerable(PropertyIds::number); } JavascriptOperators::SetProperty(pError, pError, PropertyIds::description, descriptionString, scriptContext); pError->SetNotEnumerable(PropertyIds::description); Var newTarget = callInfo.Flags & CallFlags_NewTarget ? args.Values[args.Info.Count] : args[0]; return JavascriptError::NewInstance(function, pError, callInfo, newTarget, message); }