Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
deps: update ChakraCore to chakra-core/ChakraCore@172bac86e0
Browse files Browse the repository at this point in the history
[MERGE #4614 @jackhorton] Fix error messages on errors created through the JSRT

Merge pull request #4614 from jackhorton:jsrt_error_message

This will unblock the 01/14/18 node merge pump

Reviewed-By: chakrabot <chakrabot@users.noreply.github.com>
  • Loading branch information
jackhorton authored and chakrabot committed Jan 30, 2018
1 parent 51077b4 commit 37efd78
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions deps/chakrashim/core/lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2890,9 +2890,28 @@ CHAKRA_API JsCreateNamedFunction(_In_ JsValueRef name, _In_ JsNativeFunction nat
return JsCreateEnhancedFunctionHelper<true>(nativeFunction, name, callbackState, function);
}

void SetErrorMessage(Js::ScriptContext *scriptContext, JsValueRef newError, JsValueRef message)
void SetErrorMessage(Js::ScriptContext *scriptContext, Js::JavascriptError *newError, JsValueRef message)
{
Js::JavascriptOperators::OP_SetProperty(newError, Js::PropertyIds::message, message, scriptContext);
// ECMA262 #sec-error-message
if (!Js::JavascriptOperators::IsUndefined(message))
{
Js::JavascriptString *messageStr = nullptr;
if (Js::JavascriptString::Is(message))
{
messageStr = Js::JavascriptString::FromVar(message);
}
else
{
messageStr = Js::JavascriptConversion::ToString(message, scriptContext);
}

Js::PropertyDescriptor desc;
desc.SetValue(messageStr);
desc.SetWritable(true);
desc.SetEnumerable(false);
desc.SetConfigurable(true);
Js::JavascriptOperators::SetPropertyDescriptor(newError, Js::PropertyIds::message, desc);
}
}

CHAKRA_API JsCreateError(_In_ JsValueRef message, _Out_ JsValueRef *error)
Expand All @@ -2904,7 +2923,7 @@ CHAKRA_API JsCreateError(_In_ JsValueRef message, _Out_ JsValueRef *error)
PARAM_NOT_NULL(error);
*error = nullptr;

JsValueRef newError = scriptContext->GetLibrary()->CreateError();
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateError();
SetErrorMessage(scriptContext, newError, message);
*error = newError;

Expand All @@ -2923,7 +2942,7 @@ CHAKRA_API JsCreateRangeError(_In_ JsValueRef message, _Out_ JsValueRef *error)
PARAM_NOT_NULL(error);
*error = nullptr;

JsValueRef newError = scriptContext->GetLibrary()->CreateRangeError();
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateRangeError();
SetErrorMessage(scriptContext, newError, message);
*error = newError;

Expand All @@ -2942,7 +2961,7 @@ CHAKRA_API JsCreateReferenceError(_In_ JsValueRef message, _Out_ JsValueRef *err
PARAM_NOT_NULL(error);
*error = nullptr;

JsValueRef newError = scriptContext->GetLibrary()->CreateReferenceError();
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateReferenceError();
SetErrorMessage(scriptContext, newError, message);
*error = newError;

Expand All @@ -2961,7 +2980,7 @@ CHAKRA_API JsCreateSyntaxError(_In_ JsValueRef message, _Out_ JsValueRef *error)
PARAM_NOT_NULL(error);
*error = nullptr;

JsValueRef newError = scriptContext->GetLibrary()->CreateSyntaxError();
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateSyntaxError();
SetErrorMessage(scriptContext, newError, message);
*error = newError;

Expand All @@ -2980,7 +2999,7 @@ CHAKRA_API JsCreateTypeError(_In_ JsValueRef message, _Out_ JsValueRef *error)
PARAM_NOT_NULL(error);
*error = nullptr;

JsValueRef newError = scriptContext->GetLibrary()->CreateTypeError();
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateTypeError();
SetErrorMessage(scriptContext, newError, message);
*error = newError;

Expand All @@ -2999,7 +3018,7 @@ CHAKRA_API JsCreateURIError(_In_ JsValueRef message, _Out_ JsValueRef *error)
PARAM_NOT_NULL(error);
*error = nullptr;

JsValueRef newError = scriptContext->GetLibrary()->CreateURIError();
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateURIError();
SetErrorMessage(scriptContext, newError, message);
*error = newError;

Expand Down

0 comments on commit 37efd78

Please sign in to comment.