Explorar o código

Move JavascriptErrorDebug functionality out of core.
It is used for WinRT errors only.
Rename MapAndThrowError (which does not map) to SetMessageAndThrowError

Ed Maurer %!s(int64=9) %!d(string=hai) anos
pai
achega
07f94e0c77

+ 0 - 43
lib/Parser/screrror.cpp

@@ -24,49 +24,6 @@ void CopyException (EXCEPINFO *peiDest, const EXCEPINFO *peiSource)
     }
 }
 
-/***
-*PUBLIC HRESULT GetErrorInfo
-*Purpose:
-*  Filling the given EXCEPINFO structure from the contents of
-*  the current OLE error object (if any).
-*
-*Entry:
-*  pexcepinfo = pointer to caller allocated EXCEPINFO to fillin.
-*
-*Exit:
-*  return value = HRESULT. S_OK if obtained info, else S_FALSE
-*
-*Note:
-*  This routine assumes that the given EXCEPINFO does *not* contain
-*  any strings that need to be freed before its contents are set.
-*
-***********************************************************************/
-HRESULT GetErrorInfo(EXCEPINFO *pexcepinfo)
-{
-    HRESULT hr = S_FALSE;
-
-    memset(pexcepinfo, 0, sizeof(*pexcepinfo));
-    IErrorInfo *perrinfo;
-
-    // GetErrorInfo returns S_FALSE if there is no rich error info
-    // and S_OK if there is.
-
-#ifdef _WIN32
-    if(NOERROR == (hr = GetErrorInfo(0L, &perrinfo)))
-    {
-        perrinfo->GetSource(&pexcepinfo->bstrSource);
-        perrinfo->GetDescription(&pexcepinfo->bstrDescription);
-        perrinfo->GetHelpFile(&pexcepinfo->bstrHelpFile);
-        perrinfo->GetHelpContext(&pexcepinfo->dwHelpContext);
-        perrinfo->Release();
-    }
-#endif
-    
-    return hr;
-}
-
-
-
 /***************************************************************************
 HRESULT mapping
 ***************************************************************************/

+ 0 - 2
lib/Parser/screrror.h

@@ -25,8 +25,6 @@ inline void FreeExcepInfo(EXCEPINFO *pei)
 
 void CopyException (EXCEPINFO *pexcepinfoDest, const EXCEPINFO *pexcepinfoSource);
 
-HRESULT GetErrorInfo(EXCEPINFO *pexcepinfo);
-
 HRESULT MapHr(HRESULT hr, ErrorTypeEnum * errorTypeOut = nullptr);
 
 class SRCINFO;

+ 0 - 7
lib/Runtime/Library/Chakra.Runtime.Library.vcxproj

@@ -35,11 +35,6 @@
         $(ManifestsInboxIncludeDirectory);
         %(AdditionalIncludeDirectories)
       </AdditionalIncludeDirectories>
-      <!-- For mscorlib.tlb used in JavascriptErrorDebug.cpp -->
-      <AdditionalIncludeDirectories>
-        %(AdditionalIncludeDirectories);
-        $(SdkLibPath)\clr45
-      </AdditionalIncludeDirectories>
       <PrecompiledHeader>Use</PrecompiledHeader>
       <PrecompiledHeaderFile>RuntimeLibraryPch.h</PrecompiledHeaderFile>
     </ClCompile>
@@ -155,7 +150,6 @@
     <ClCompile Include="$(MSBuildThisFileDirectory)UriHelper.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)ExternalLibraryBase.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)IntlEngineInterfaceExtensionObject.cpp" />
-    <ClCompile Include="$(MSBuildThisFileDirectory)JavascriptErrorDebug.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)JavascriptListIterator.cpp" />
   </ItemGroup>
   <ItemGroup>
@@ -164,7 +158,6 @@
     <ClInclude Include="..\SerializableFunctionFields.h" />
     <ClInclude Include="ExternalLibraryBase.h" />
     <ClInclude Include="IntlEngineInterfaceExtensionObject.h" />
-    <ClInclude Include="JavascriptErrorDebug.h" />
     <ClInclude Include="JavascriptListIterator.h" />
     <ClInclude Include="JavascriptSimdObject.h" />
     <ClInclude Include="JavascriptSimdType.h" />

+ 0 - 2
lib/Runtime/Library/Chakra.Runtime.Library.vcxproj.filters

@@ -95,7 +95,6 @@
     <ClCompile Include="$(MSBuildThisFileDirectory)NullEnumerator.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)ExternalLibraryBase.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)IntlEngineInterfaceExtensionObject.cpp" />
-    <ClCompile Include="$(MSBuildThisFileDirectory)JavascriptErrorDebug.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)JavascriptSimdType.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)JavascriptSimdInt16x8.cpp" />
     <ClCompile Include="$(MSBuildThisFileDirectory)SimdInt16x8Lib.cpp" />
@@ -223,7 +222,6 @@
     <ClInclude Include="RuntimeLibraryPch.h" />
     <ClInclude Include="ExternalLibraryBase.h" />
     <ClInclude Include="IntlEngineInterfaceExtensionObject.h" />
-    <ClInclude Include="JavascriptErrorDebug.h" />
     <ClInclude Include="JavascriptStringObject.h" />
     <ClInclude Include="NullEnumerator.h" />
     <ClInclude Include="JavascriptSimdType.h" />

+ 23 - 72
lib/Runtime/Library/JavascriptError.cpp

@@ -4,7 +4,6 @@
 //-------------------------------------------------------------------------------------------------------
 #include "RuntimeLibraryPch.h"
 #include "errstr.h"
-#include "Library/JavascriptErrorDebug.h"
 
 #ifdef ERROR_TRACE
 #define TRACE_ERROR(...) { Trace(__VA_ARGS__); }
@@ -289,69 +288,38 @@ namespace Js
         JavascriptError::MapAndThrowError(scriptContext, hr, errorType, nullptr);
     }
 
-    void __declspec(noreturn) JavascriptError::MapAndThrowError(ScriptContext* scriptContext, HRESULT hr, ErrorTypeEnum errorType, EXCEPINFO* pei, IErrorInfo * perrinfo, RestrictedErrorStrings * proerrstr, bool useErrInfoDescription)
+    void __declspec(noreturn) JavascriptError::MapAndThrowError(ScriptContext* scriptContext, HRESULT hr, ErrorTypeEnum errorType, EXCEPINFO* pei)
     {
-        JavascriptError* pError = MapError(scriptContext, errorType, perrinfo, proerrstr);
-        MapAndThrowError(scriptContext, pError, hr, pei, useErrInfoDescription);
+        JavascriptError* pError = MapError(scriptContext, errorType);
+        SetMessageAndThrowError(scriptContext, pError, hr, pei);
     }
 
-    void __declspec(noreturn) JavascriptError::MapAndThrowError(ScriptContext* scriptContext, JavascriptError *pError, int32 hCode, EXCEPINFO* pei, bool useErrInfoDescription/* = false*/)
+    void __declspec(noreturn) JavascriptError::SetMessageAndThrowError(ScriptContext* scriptContext, JavascriptError *pError, int32 hCode, EXCEPINFO* pei)
     {
-        Assert(pError != nullptr);
-
         PCWSTR varName = (pei ? pei->bstrDescription : nullptr);
-#ifdef _WIN32
-        if (useErrInfoDescription)
-        {
-            JavascriptErrorDebug::SetErrorMessage(pError, hCode, varName, scriptContext);
-        }
-        else
-#endif
+
+        JavascriptError::SetErrorMessage(pError, hCode, varName, scriptContext);
+
+        if (pei)
         {
-            Assert(!useErrInfoDescription);
-            JavascriptError::SetErrorMessage(pError, hCode, varName, scriptContext);
+            FreeExcepInfo(pei);
         }
-        if (pei) FreeExcepInfo(pei);
-        JavascriptExceptionOperators::Throw(pError, scriptContext);
-    }
 
-#ifdef _WIN32
-#define CREATE_ERROR(create_method, get_type_method, err_type)   \
-    if (perrinfo) \
-    { \
-        JavascriptErrorDebug *pErrorDebug = RecyclerNewFinalized(library->GetRecycler(), JavascriptErrorDebug, perrinfo, library->get_type_method()); \
-        JavascriptError::SetErrorType(pErrorDebug, err_type); \
-        if (proerrstr) \
-        { \
-            pErrorDebug->SetRestrictedErrorStrings(proerrstr); \
-        } \
-        pError = static_cast<JavascriptError*>(pErrorDebug); \
-    } \
-    else \
-    { \
-        pError = library->create_method(); \
-    } 
-#else
-#define CREATE_ERROR(create_method, get_type_method, err_type)   \
-    { \
-        Assert(perrinfo == nullptr); \
-        pError = library->create_method(); \
+        JavascriptExceptionOperators::Throw(pError, scriptContext);
     }
-#endif
 
 #define THROW_ERROR_IMPL(err_method, create_method, get_type_method, err_type) \
-    static JavascriptError* create_method(ScriptContext* scriptContext, IErrorInfo* perrinfo, RestrictedErrorStrings * proerrstr) \
+    static JavascriptError* create_method(ScriptContext* scriptContext) \
     { \
         JavascriptLibrary *library = scriptContext->GetLibrary(); \
-        JavascriptError *pError = nullptr; \
-        CREATE_ERROR(create_method, get_type_method, err_type);  \
+        JavascriptError *pError = library->create_method(); \
         return pError; \
     } \
     \
-    void __declspec(noreturn) JavascriptError::err_method(ScriptContext* scriptContext, int32 hCode, EXCEPINFO* pei, IErrorInfo* perrinfo, RestrictedErrorStrings * proerrstr, bool useErrInfoDescription) \
+    void __declspec(noreturn) JavascriptError::err_method(ScriptContext* scriptContext, int32 hCode, EXCEPINFO* pei) \
     { \
-        JavascriptError *pError = create_method(scriptContext, perrinfo, proerrstr); \
-        MapAndThrowError(scriptContext, pError, hCode, pei, useErrInfoDescription); \
+        JavascriptError *pError = create_method(scriptContext); \
+        SetMessageAndThrowError(scriptContext, pError, hCode, pei); \
     } \
     \
     void __declspec(noreturn) JavascriptError::err_method(ScriptContext* scriptContext, int32 hCode, PCWSTR varName) \
@@ -390,34 +358,22 @@ namespace Js
     THROW_ERROR_IMPL(ThrowURIError, CreateURIError, GetURIErrorType, kjstURIError)
 #undef THROW_ERROR_IMPL
 
-    JavascriptError* JavascriptError::MapError(ScriptContext* scriptContext, ErrorTypeEnum errorType, IErrorInfo * perrinfo /*= nullptr*/, RestrictedErrorStrings * proerrstr /*= nullptr*/)
+    JavascriptError* JavascriptError::MapError(ScriptContext* scriptContext, ErrorTypeEnum errorType)
     {
         switch (errorType)
         {
         case kjstError:
-          return CreateError(scriptContext, perrinfo, proerrstr);
+          return CreateError(scriptContext);
         case kjstTypeError:
-          return CreateTypeError(scriptContext, perrinfo, proerrstr);
+          return CreateTypeError(scriptContext);
         case kjstRangeError:
-          return CreateRangeError(scriptContext, perrinfo, proerrstr);
+          return CreateRangeError(scriptContext);
         case kjstSyntaxError:
-          return CreateSyntaxError(scriptContext, perrinfo, proerrstr);
+          return CreateSyntaxError(scriptContext);
         case kjstReferenceError:
-          return CreateReferenceError(scriptContext, perrinfo, proerrstr);
+          return CreateReferenceError(scriptContext);
         case kjstURIError:
-          return CreateURIError(scriptContext, perrinfo, proerrstr);
-#ifdef ENABLE_PROJECTION
-        case kjstWinRTError:
-          if (scriptContext->GetConfig()->IsWinRTEnabled())
-          {
-              return scriptContext->GetHostScriptContext()->CreateWinRTError(perrinfo, proerrstr);
-          }
-          else
-          {
-              return CreateError(scriptContext, perrinfo, proerrstr);
-          }
-          break;
-#endif
+          return CreateURIError(scriptContext);
         default:
             AssertMsg(FALSE, "Invalid error type");
             __assume(false);
@@ -691,7 +647,7 @@ namespace Js
         se->GetError(&hrParser, &ei);
 
         JavascriptError* pError = MapParseError(scriptContext, ei.scode);
-        JavascriptError::MapAndThrowError(scriptContext, pError, ei.scode, &ei);
+        JavascriptError::SetMessageAndThrowError(scriptContext, pError, ei.scode, &ei);
     }
 
     ErrorTypeEnum JavascriptError::MapParseError(int32 hCode)
@@ -859,11 +815,6 @@ namespace Js
         case kjstURIError:
             jsNewError = targetJavascriptLibrary->CreateURIError();
             break;
-#ifdef ENABLE_PROJECTION
-        case kjstWinRTError:
-            jsNewError = targetJavascriptLibrary->GetScriptContext()->GetHostScriptContext()->CreateWinRTError(nullptr, nullptr);
-            break;
-#endif
 
         case kjstCustomError:
         default:

+ 6 - 6
lib/Runtime/Library/JavascriptError.h

@@ -80,18 +80,18 @@ namespace Js
         static Var EntryToString(RecyclableObject* function, CallInfo callInfo, ...);
 
         static void __declspec(noreturn) MapAndThrowError(ScriptContext* scriptContext, HRESULT hr);
-        static void __declspec(noreturn) MapAndThrowError(ScriptContext* scriptContext, HRESULT hr, ErrorTypeEnum errorType, EXCEPINFO *ei, IErrorInfo * perrinfo = nullptr, RestrictedErrorStrings * proerrstr = nullptr, bool useErrInfoDescription = false);
-        static void __declspec(noreturn) MapAndThrowError(ScriptContext* scriptContext, JavascriptError *pError, int32 hCode, EXCEPINFO* pei, bool useErrInfoDescription = false);
-        static JavascriptError* MapError(ScriptContext* scriptContext, ErrorTypeEnum errorType, IErrorInfo * perrinfo = nullptr, RestrictedErrorStrings * proerrstr = nullptr);
+        static void __declspec(noreturn) MapAndThrowError(ScriptContext* scriptContext, HRESULT hr, ErrorTypeEnum errorType, EXCEPINFO *ei);
+        static void __declspec(noreturn) SetMessageAndThrowError(ScriptContext* scriptContext, JavascriptError *pError, int32 hCode, EXCEPINFO* pei);
+        static JavascriptError* MapError(ScriptContext* scriptContext, ErrorTypeEnum errorType);
 
 #define THROW_ERROR_DECL(err_method) \
-        static void __declspec(noreturn) err_method(ScriptContext* scriptContext, int32 hCode, EXCEPINFO* ei, IErrorInfo* perrinfo = nullptr, RestrictedErrorStrings* proerrstr = nullptr, bool useErrInfoDescription = false); \
+        static void __declspec(noreturn) err_method(ScriptContext* scriptContext, int32 hCode, EXCEPINFO* ei); \
         static void __declspec(noreturn) err_method(ScriptContext* scriptContext, int32 hCode, PCWSTR varName = nullptr); \
         static void __declspec(noreturn) err_method(ScriptContext* scriptContext, int32 hCode, JavascriptString* varName); \
         static void __declspec(noreturn) err_method##Var(ScriptContext* scriptContext, int32 hCode, ...);
 
         THROW_ERROR_DECL(ThrowError)
-        THROW_ERROR_DECL(ThrowEvalError)
+        THROW_ERROR_DECL(ThrowEvalError)    //this is unused and should be removed
         THROW_ERROR_DECL(ThrowRangeError)
         THROW_ERROR_DECL(ThrowReferenceError)
         THROW_ERROR_DECL(ThrowSyntaxError)
@@ -139,7 +139,7 @@ namespace Js
 
         static int32 GetErrorNumberFromResourceID(int32 resourceId);
 
-        JavascriptError* CreateNewErrorOfSameType(JavascriptLibrary* targetJavascriptLibrary);
+        virtual JavascriptError* CreateNewErrorOfSameType(JavascriptLibrary* targetJavascriptLibrary);
         JavascriptError* CloneErrorMsgAndNumber(JavascriptLibrary* targetJavascriptLibrary);
         static void TryThrowTypeError(ScriptContext * checkScriptContext, ScriptContext * scriptContext, int32 hCode, PCWSTR varName = nullptr);
         static JavascriptError* CreateFromCompileScriptException(ScriptContext* scriptContext, CompileScriptException* cse);

+ 0 - 409
lib/Runtime/Library/JavascriptErrorDebug.cpp

@@ -1,409 +0,0 @@
-//-------------------------------------------------------------------------------------------------------
-// Copyright (C) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
-//-------------------------------------------------------------------------------------------------------
-#include "RuntimeLibraryPch.h"
-#include <strsafe.h>
-#include "restrictederrorinfo.h"
-#include "errstr.h"
-#include "Library/JavascriptErrorDebug.h"
-
-#if defined(_MSC_VER) && !defined(__clang__)
-// Temporarily undefining "null" (defined in Common.h) to avoid compile errors when importing mscorlib.tlb
-#import <mscorlib.tlb> raw_interfaces_only \
-    rename("Assert","CLRAssert") rename("ReportEvent","CLRReportEvent") rename("Debugger","CLRDebugger")
-#endif
-
-namespace Js
-{
-#if defined(_MSC_VER) && !defined(__clang__)
-    using namespace mscorlib;
-#endif
-
-    __declspec(thread)  char16 JavascriptErrorDebug::msgBuff[512];
-
-    bool JavascriptErrorDebug::Is(Var aValue)
-    {
-        AssertMsg(aValue != NULL, "Error is NULL - did it come from an out of memory exception?");
-        if (JavascriptOperators::GetTypeId(aValue) == TypeIds_Error)
-        {
-            JavascriptError * error = JavascriptError::FromVar(aValue);
-            return error->HasDebugInfo();
-        }
-        return false;
-    }
-
-    // Info: Differentiates between JavascriptError and JavascriptErrorDebug
-    bool JavascriptErrorDebug::HasDebugInfo()
-    {
-        return true;
-    }
-
-    // Info: Finalizer to release stored IErrorInfo
-    void JavascriptErrorDebug::Finalize(bool isShutdown)
-    {
-        // Finalize can be called multiple times (from recycler and from ScriptSite::Close)
-        // Check if that is the case and don't do anything
-        if (isShutdown)
-        {
-            return;
-        }
-        if (pErrorInfo == nullptr)
-        {
-            return ;
-        }
-        pErrorInfo->Release();
-        pErrorInfo = nullptr;
-        if (restrictedStrings.restrictedErrStr != nullptr)
-        {
-            SysFreeString(restrictedStrings.restrictedErrStr);
-            restrictedStrings.restrictedErrStr = nullptr;
-        }
-        if (restrictedStrings.referenceStr != nullptr)
-        {
-            SysFreeString(restrictedStrings.referenceStr);
-            restrictedStrings.referenceStr = nullptr;
-        }
-        if (restrictedStrings.capabilitySid != nullptr)
-        {
-            SysFreeString(restrictedStrings.capabilitySid);
-            restrictedStrings.capabilitySid = nullptr;
-        }
-    }
-
-    void JavascriptErrorDebug::Dispose(bool isShutdown)
-    {
-    }
-
-#ifdef ENABLE_PROJECTION
-    void JavascriptErrorDebug::ClearErrorInfo(ScriptContext* scriptContext)
-    {
-        HRESULT hr = scriptContext->GetThreadContext()->GetWinRTErrorLibrary()->RoClearError();
-
-        // If we fail to create the delay-load library or fail to find RoClearError in it, fallback to Win8 behavior.
-        if (FAILED(hr))
-        {
-            IErrorInfo * perrinfo;
-            if(NOERROR == (hr = GetErrorInfo(0L, &perrinfo)))
-            {
-                perrinfo->Release();
-            }
-        }
-    }
-#endif
-
-    // Info:        Map and Throw a JavascriptError(Debug) containing restricted error information, if available
-    // Parameters:  scriptContext - the script context
-    //              hr - HRESULT of the error to be thrown
-    void __declspec(noreturn) JavascriptErrorDebug::MapAndThrowErrorWithInfo(ScriptContext* scriptContext, HRESULT hr)
-    {
-        // Initialize error type to kjstWinRTError if WinRT is enabled, or to kjstError otherwise.
-#ifdef ENABLE_PROJECTION
-        ErrorTypeEnum errorType = scriptContext->GetConfig()->IsWinRTEnabled() ? kjstWinRTError : kjstError;
-#else
-        ErrorTypeEnum errorType = kjstError;
-#endif
-        // Get error type if hr is a runtime error.
-        GetErrorTypeFromNumber(hr, &errorType);
-
-        EXCEPINFO excepinfo;
-        EXCEPINFO baseline;
-        memset(&baseline, 0, sizeof(baseline));
-        RestrictedErrorStrings roerrstr;
-        IErrorInfo * perrinfo = nullptr;
-        HRESULT result = GetExcepAndErrorInfo(scriptContext, hr, &excepinfo, &roerrstr, &perrinfo);
-        // If there is WinRT specific information for this error, throw an error including it
-        if (NOERROR == result)
-        {
-            MapAndThrowError(scriptContext, hr, errorType, &excepinfo, perrinfo, &roerrstr, true);
-        }
-        // If there is no restricted info, but unrestricted exception info was obtained,
-        // throw an error with the exception info only
-        else if(memcmp(&excepinfo, &baseline, sizeof(baseline)) != 0)
-        {
-            Assert(!perrinfo);
-            MapAndThrowError(scriptContext, hr, errorType, &excepinfo, nullptr, nullptr, true);
-        }
-        // If no specialized info was obtained, throw an error by HRESULT and type only.
-        else
-        {
-            MapAndThrowError(scriptContext, hr, errorType, nullptr, nullptr, nullptr, true);
-        }
-    }
-
-    void JavascriptErrorDebug::SetErrorMessage(JavascriptError *pError, HRESULT hr, PCWSTR varDescription, ScriptContext* scriptContext)
-    {
-        Assert(FAILED(hr));
-
-        char16* allocatedString = nullptr;
-        BSTR restrictedDescription = nullptr;
-        BSTR message = nullptr;
-        size_t length = 1; // +1 for null character
-
-#ifdef ENABLE_PROJECTION
-        // Get the restricted error string - but only if the WinRT is enabled and we are targeting WinBlue+.
-        if (JavascriptErrorDebug::Is(pError)
-            && scriptContext->GetConfig()->IsWinRTEnabled()
-            && scriptContext->GetConfig()->GetProjectionConfig() != nullptr
-            && scriptContext->GetConfig()->GetProjectionConfig()->IsTargetWindowsBlueOrLater())
-        {
-            restrictedDescription = JavascriptErrorDebug::FromVar(pError)->GetRestrictedErrorString();
-            length += SysStringLen(restrictedDescription);
-        }
-#endif
-
-        if (varDescription != nullptr)
-        {
-            length += wcslen(varDescription);
-        }
-        else
-        {
-            if (FACILITY_CONTROL == HRESULT_FACILITY(hr))
-            {
-                message = BstrGetResourceString(hr);
-            }
-            if (message == nullptr)
-            {
-                // Default argument array of empty strings, for CLR parity
-                DWORD_PTR pArgs[] = { (DWORD_PTR)_u(""), (DWORD_PTR)_u(""), (DWORD_PTR)_u(""), (DWORD_PTR)_u(""), (DWORD_PTR)_u(""),
-                    (DWORD_PTR)_u(""), (DWORD_PTR)_u(""), (DWORD_PTR)_u(""), (DWORD_PTR)_u(""), (DWORD_PTR)_u("") };
-
-                if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
-                    FORMAT_MESSAGE_ARGUMENT_ARRAY,
-                    NULL,
-                    hr,
-                    0,
-                    msgBuff,
-                    _countof(msgBuff),
-                    (va_list*)pArgs))
-                {
-                    message = SysAllocString(msgBuff);
-                }
-            }
-            if (message == nullptr)
-            {
-                message = BstrGetResourceString(IDS_UNKNOWN_RUNTIME_ERROR);
-            }
-            if (message != nullptr)
-            {
-                length += SysStringLen(message);
-            }
-        }
-
-        // If length == 1, we didn't find any description strings - leave allocatedString null.
-        if (length > 1)
-        {
-             // If we have a restricted description, the error message format is ("%s\r\n%s", message, restrictedMessage).
-             if (restrictedDescription != nullptr)
-             {
-                 // length should be longer by 2 characters to handle the \r\n
-                 allocatedString = RecyclerNewArrayLeaf(scriptContext->GetRecycler(), char16, length + 2);
-                 StringCchPrintfW(allocatedString, length + 2, _u("%s\r\n%s"), varDescription ? varDescription : message, restrictedDescription);
-             }
-             else
-             {
-                 allocatedString = RecyclerNewArrayLeaf(scriptContext->GetRecycler(), char16, length);
-                 wcscpy_s(allocatedString, length, varDescription ? varDescription : message);
-             }
-        }
-
-        if (restrictedDescription != nullptr)
-        {
-            SysFreeString(restrictedDescription);
-            restrictedDescription = nullptr;
-        }
-
-        if (message != nullptr)
-        {
-            SysFreeString(message);
-            message = nullptr;
-        }
-
-        JavascriptError::SetErrorMessageProperties(pError, hr, allocatedString, scriptContext);
-    }
-
-    // Info:        Gets both unrestricted and restricted error info
-    // Parameters:  scriptContext - the script context
-    //              pexcepinfo - the exception info of the error (unrestricted)
-    //              proerrstr - the winrt specific error strings (restricted)
-    //              pperrinfo - the IErrorInfo object
-    // Returns:     Failed HRESULT - if GetErrorInfo or QI fail
-    //              Success - otherwise
-    HRESULT JavascriptErrorDebug::GetExcepAndErrorInfo(ScriptContext* scriptContext, HRESULT hrReturned, EXCEPINFO *pexcepinfo, RestrictedErrorStrings * proerrstr, IErrorInfo ** pperrinfo)
-    {
-        HRESULT hr;
-        HRESULT hrResult;
-        bool errorInfoMatch = false;
-
-        memset(pexcepinfo, 0, sizeof(*pexcepinfo));
-        memset(proerrstr, 0, sizeof(*proerrstr));
-        *pperrinfo = nullptr;
-
-#if defined(_MSC_VER) && !defined(__clang__)
-        // GetErrorInfo returns S_FALSE if there is no rich error info
-        // and S_OK if there is.
-        IErrorInfo * perrinfo;
-        if(NOERROR != (hr = GetErrorInfo(0L, &perrinfo)))
-        {
-            return hr;
-        }
-        // Fill Exception info
-        perrinfo->GetSource(&pexcepinfo->bstrSource);
-        perrinfo->GetDescription(&pexcepinfo->bstrDescription);
-        perrinfo->GetHelpFile(&pexcepinfo->bstrHelpFile);
-        perrinfo->GetHelpContext(&pexcepinfo->dwHelpContext);
-
-        // Initialize restricted strings
-        proerrstr->restrictedErrStr = nullptr;
-        proerrstr->referenceStr = nullptr;
-        proerrstr->capabilitySid = nullptr;
-
-        BSTR bstrErr = nullptr;
-        BSTR bstrRestrictedErr = nullptr;
-        BSTR bstrCapabilitySid = nullptr;
-        BSTR bstrReference = nullptr;
-
-        IRestrictedErrorInfo * pROErrorInfo = nullptr;
-        _Exception * pCLRException = nullptr;
-        hr = perrinfo->QueryInterface(__uuidof(IRestrictedErrorInfo), reinterpret_cast<void**>(&pROErrorInfo));
-        if (SUCCEEDED(hr))
-        {
-            // Get restricted error strings from IRestrictedErrorInfo
-            HRESULT hrErr = S_OK;
-            hrResult = pROErrorInfo->GetErrorDetails(&bstrErr, &hrErr, &bstrRestrictedErr, &bstrCapabilitySid);
-            if (SUCCEEDED(hrResult))
-            {
-                errorInfoMatch = (hrErr == hrReturned);
-                if (errorInfoMatch)
-                {
-                    if (nullptr != bstrRestrictedErr)
-                    {
-                        proerrstr->restrictedErrStr = bstrRestrictedErr;
-                        bstrRestrictedErr = nullptr;
-                    }
-                    if (nullptr != bstrCapabilitySid)
-                    {
-                        proerrstr->capabilitySid = bstrCapabilitySid;
-                        bstrCapabilitySid = nullptr;
-                    }
-                }
-            }
-            hrResult = pROErrorInfo->GetReference(&bstrReference);
-            if (SUCCEEDED(hrResult) && errorInfoMatch)
-            {
-                if (nullptr != bstrReference)
-                {
-                    proerrstr->referenceStr = bstrReference;
-                    bstrReference = nullptr;
-                }
-            }
-        }
-        else
-        {
-            hr = perrinfo->QueryInterface(__uuidof(_Exception), reinterpret_cast<void**>(&pCLRException));
-            if(FAILED(hr))
-            {
-                perrinfo->Release();
-                return hr;
-            }
-            hrResult = pCLRException->get_Message(&bstrRestrictedErr);
-            if (SUCCEEDED(hrResult))
-            {
-                errorInfoMatch = true;
-                if (nullptr != bstrRestrictedErr)
-                {
-                    proerrstr->restrictedErrStr = bstrRestrictedErr;
-                    bstrRestrictedErr = nullptr;
-                }
-            }
-        }
-        if (nullptr != bstrErr)
-        {
-            SysFreeString(bstrErr);
-            bstrErr = nullptr;
-        }
-        if (nullptr != bstrRestrictedErr)
-        {
-            SysFreeString(bstrRestrictedErr);
-            bstrRestrictedErr = nullptr;
-        }
-        if (nullptr != bstrCapabilitySid)
-        {
-            SysFreeString(bstrCapabilitySid);
-            bstrCapabilitySid = nullptr;
-        }
-        if (nullptr != bstrReference)
-        {
-            SysFreeString(bstrReference);
-            bstrReference = nullptr;
-        }
-
-        if (!errorInfoMatch)
-        {
-            if (nullptr != pexcepinfo->bstrSource)
-            {
-                SysFreeString(pexcepinfo->bstrSource);
-                pexcepinfo->bstrSource = nullptr;
-            }
-            if (nullptr != pexcepinfo->bstrDescription)
-            {
-                SysFreeString(pexcepinfo->bstrDescription);
-                pexcepinfo->bstrDescription = nullptr;
-            }
-            if (nullptr != pexcepinfo->bstrHelpFile)
-            {
-                SysFreeString(pexcepinfo->bstrHelpFile);
-                pexcepinfo->bstrHelpFile = nullptr;
-            }
-            perrinfo->Release();
-            perrinfo = nullptr;
-            hr = S_FALSE;
-        }
-
-        if (nullptr != pROErrorInfo)
-        {
-            pROErrorInfo->Release();
-        }
-        if (nullptr != pCLRException)
-        {
-            pCLRException->Release();
-        }
-        *pperrinfo = perrinfo;
-        return hr;
-#else
-        // xplat-todo: Find out if we can implement richer error info on Linux
-        return hr;
-#endif
-    }
-
-    void JavascriptErrorDebug::SetErrorInfo()
-    {
-        IErrorInfo * pErrorInfo = GetRestrictedErrorInfo();
-
-        if (!pErrorInfo)
-        {
-            return;
-        }
-
-        ::SetErrorInfo(0L, pErrorInfo);
-    }
-
-    void JavascriptErrorDebug::GetErrorTypeFromNumber(HRESULT hr, ErrorTypeEnum * errorTypeOut)
-    {
-        if (errorTypeOut == nullptr)
-        {
-            return;
-        }
-        switch ((HRESULT)hr)
-        {
-#define RT_ERROR_MSG(name, errnum, str1, str2, jst, errorNumSource) \
-        case name: \
-        *errorTypeOut = jst; \
-        break;
-#define RT_PUBLICERROR_MSG(name, errnum, str1, str2, jst, errorNumSource) RT_ERROR_MSG(name, errnum, str1, str2, jst, errorNumSource)
-#include "rterrors.h"
-#undef RT_PUBLICERROR_MSG
-#undef RT_ERROR_MSG
-        }
-    }
-}

+ 0 - 97
lib/Runtime/Library/JavascriptErrorDebug.h

@@ -1,97 +0,0 @@
-//-------------------------------------------------------------------------------------------------------
-// Copyright (C) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
-//-------------------------------------------------------------------------------------------------------
-#pragma once
-
-namespace Js
-{
-    // Specialized Error Object, containing WinRT specific information.
-    // Not applicable for non-Windows platforms
-    // TODO: Move this out of ChakraCore
-#ifdef _WIN32
-    class JavascriptErrorDebug : public JavascriptError
-    {
-    protected:
-        DEFINE_VTABLE_CTOR(JavascriptErrorDebug, JavascriptError);
-    public:
-        JavascriptErrorDebug(IErrorInfo* perrinfo, DynamicType* type, BOOL isExternalError = FALSE) :
-          JavascriptError(type, isExternalError)
-        {
-            Assert(perrinfo);
-            pErrorInfo = perrinfo;
-            restrictedStrings.referenceStr = nullptr;
-            restrictedStrings.restrictedErrStr = nullptr;
-            restrictedStrings.capabilitySid = nullptr;
-        }
-
-        static bool Is(Var aValue);
-        static JavascriptErrorDebug* FromVar(Var aValue)
-        {
-            AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptErrorDebug'");
-
-            return static_cast<JavascriptErrorDebug *>(JavascriptError::FromVar(aValue));
-        }
-
-        // For differentiating between JavascriptError and JavascriptErrorDebug
-        bool HasDebugInfo();
-
-        void Finalize(bool isShutdown) override;
-        void Dispose(bool isShutdown) override;
-
-        static void __declspec(noreturn) MapAndThrowErrorWithInfo(ScriptContext* scriptContext, HRESULT hr);
-#ifdef ENABLE_PROJECTION
-        static void ClearErrorInfo(ScriptContext* scriptContext);
-#endif
-
-        static void SetErrorMessage(JavascriptError *pError, HRESULT errCode, PCWSTR varDescription, ScriptContext* scriptContext);
-
-        void SetRestrictedErrorStrings(RestrictedErrorStrings * proerrstr)
-        {
-            Assert(proerrstr);
-            restrictedStrings.referenceStr = proerrstr->referenceStr;
-            restrictedStrings.restrictedErrStr = proerrstr->restrictedErrStr;
-            restrictedStrings.capabilitySid = proerrstr->capabilitySid;
-        }
-
-        BSTR GetRestrictedErrorString()
-        {
-            if (restrictedStrings.restrictedErrStr)
-            {
-                return SysAllocString(restrictedStrings.restrictedErrStr);
-            }
-            return nullptr;
-        }
-
-        BSTR GetRestrictedErrorReference()
-        {
-            if (restrictedStrings.referenceStr)
-            {
-                return SysAllocString(restrictedStrings.referenceStr);
-            }
-            return nullptr;
-        }
-
-        BSTR GetCapabilitySid()
-        {
-            if (restrictedStrings.capabilitySid)
-            {
-                return SysAllocString(restrictedStrings.capabilitySid);
-            }
-            return nullptr;
-        }
-
-        IErrorInfo * GetRestrictedErrorInfo() { return pErrorInfo; }
-
-        void SetErrorInfo();
-
-    private:
-        DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(JavascriptErrorDebug);
-        static void GetErrorTypeFromNumber(HRESULT hr, ErrorTypeEnum * errorTypeOut);
-        static HRESULT GetExcepAndErrorInfo(ScriptContext* scriptContext, HRESULT hrReturned, EXCEPINFO *pexcepinfo, RestrictedErrorStrings * proerrstr, IErrorInfo ** pperrinfo);
-        RestrictedErrorStrings restrictedStrings; // WinRT specific error strings
-        IErrorInfo * pErrorInfo; // reference to the original IErrorInfo object
-        static __declspec(thread)  char16 msgBuff[512];
-    };
-#endif
-}

+ 36 - 0
lib/Runtime/Library/JavascriptLibrary.cpp

@@ -798,6 +798,42 @@ namespace Js
         }
     }
 
+    DynamicType* JavascriptLibrary::GetErrorType(ErrorTypeEnum typeToFind) const
+    {
+        switch (typeToFind)
+        {
+        case kjstError:
+            return GetErrorType();
+            break;
+
+        case kjstEvalError:
+            return GetEvalErrorType();
+            break;
+
+        case kjstRangeError:
+            return GetRangeErrorType();
+            break;
+
+        case kjstReferenceError:
+            return GetReferenceErrorType();
+            break;
+
+        case kjstSyntaxError:
+            return GetSyntaxErrorType();
+            break;
+
+        case kjstTypeError:
+            return GetTypeErrorType();
+            break;
+
+        case kjstURIError:
+            return GetURIErrorType();
+            break;
+        }
+
+        return nullptr;
+    }
+
     template<bool isNameAvailable, bool isPrototypeAvailable>
     class InitializeFunctionDeferredTypeHandlerFilter
     {

+ 1 - 0
lib/Runtime/Library/JavascriptLibrary.h

@@ -694,6 +694,7 @@ namespace Js
         DynamicType * GetDebugFuncExecutorInDisposeObjectType() { return debugFuncExecutorInDisposeObjectType; }
 #endif
 
+        DynamicType* GetErrorType(ErrorTypeEnum typeToCreate) const;
         StaticType  * GetBooleanTypeStatic() const { return booleanTypeStatic; }
         DynamicType * GetBooleanTypeDynamic() const { return booleanTypeDynamic; }
         DynamicType * GetDateType() const { return dateType; }