HRESULT JavascriptError::GetRuntimeError(RecyclableObject* errorObject, __out_opt LPCWSTR * pMessage) { // Only report the error number if it is a runtime error HRESULT hr = JSERR_UncaughtException; ScriptContext* scriptContext = errorObject->GetScriptContext(); // This version needs to be called in script. Assert(scriptContext->GetThreadContext()->IsScriptActive()); Var number = JavascriptOperators::GetProperty(errorObject, Js::PropertyIds::number, scriptContext, NULL); if (TaggedInt::Is(number)) { hr = TaggedInt::ToInt32(number); } else if (JavascriptNumber::Is_NoTaggedIntCheck(number)) { hr = (HRESULT)JavascriptNumber::GetValue(number); } if (!FAILED(hr)) { hr = E_FAIL; } if (pMessage != NULL) { *pMessage = _u(""); // default to have IE load the error message, by returning empty-string // The description property always overrides any error message Var description = Js::JavascriptOperators::GetProperty(errorObject, Js::PropertyIds::description, scriptContext, NULL); if (JavascriptString::Is(description)) { // Always report the description to IE if it is a string, even if the user sets it JavascriptString * messageString = JavascriptString::FromVar(description); *pMessage = messageString->GetSz(); } else if (Js::JavascriptError::Is(errorObject) && Js::JavascriptError::FromVar(errorObject)->originalRuntimeErrorMessage != nullptr) { // use the runtime error message *pMessage = Js::JavascriptError::FromVar(errorObject)->originalRuntimeErrorMessage; } else if (FACILITY_CONTROL == HRESULT_FACILITY(hr)) { // User might have create it's own Error object with JS error code, try to load the // resource string from the HResult by returning null; *pMessage = nullptr; } } // If neither the description or original runtime error message is set, and there are no error message. // Then just return false and we will report Uncaught exception to IE. return hr; }