Kaynağa Gözat

xplat: Enable ES6Module support

Oguz Bastemur 9 yıl önce
ebeveyn
işleme
629a06531e

+ 3 - 2
bin/ChakraCore/ChakraCoreShared.cpp

@@ -8,7 +8,7 @@
 #include "TestHooks.h"
 
 #ifdef __APPLE__
-// dummy usage of JSRT to force export JSRT on dylib
+// dummy usage of some Jsrt to force export Jsrt on dylib
 #include "ChakraCore.h"
 void DummyJSRTCall()
 {
@@ -16,6 +16,7 @@ void DummyJSRTCall()
     JsRuntimeAttributes attr;
     JsCreateRuntime(attr, nullptr, runtime);
     JsDiagStartDebugging(runtime, nullptr, nullptr);
+    JsInitializeModuleRecord(nullptr, nullptr, nullptr);
 }
 #endif
 
@@ -31,4 +32,4 @@ EXTERN_C BOOL WINAPI DllMain(HINSTANCE hmod, DWORD dwReason, PVOID pvReserved)
     return TRUE;
 }
 
-static_assert(__LINE__ == 34, "You shouldn't add anything to this file or ChakraCoreDllFunc.cpp. Please consider again!");
+static_assert(__LINE__ == 35, "You shouldn't add anything to this file or ChakraCoreDllFunc.cpp. Please consider again!");

+ 5 - 5
bin/ch/ChakraRtInterface.h

@@ -339,14 +339,14 @@ public:
     static JsErrorCode WINAPI JsDiagGetObjectFromHandle(unsigned int handle, JsValueRef * handleObject) { return HOOK_JS_API(DiagGetObjectFromHandle(handle, handleObject)); }
     static JsErrorCode WINAPI JsDiagEvaluateUtf8(const char * expression, unsigned int stackFrameIndex, JsValueRef * evalResult) { return HOOK_JS_API(DiagEvaluateUtf8(expression, stackFrameIndex, evalResult)); }
     static JsErrorCode WINAPI JsParseModuleSource(JsModuleRecord requestModule, JsSourceContext sourceContext, byte* sourceText, unsigned int sourceLength, JsParseModuleSourceFlags sourceFlag, JsValueRef* exceptionValueRef) {
-        return m_jsApiHooks.pfJsrtParseModuleSource(requestModule, sourceContext, sourceText, sourceLength, sourceFlag, exceptionValueRef);
+        return HOOK_JS_API(ParseModuleSource(requestModule, sourceContext, sourceText, sourceLength, sourceFlag, exceptionValueRef));
     }
-    static JsErrorCode WINAPI JsModuleEvaluation(JsModuleRecord requestModule, JsValueRef* result) { return m_jsApiHooks.pfJsrtModuleEvaluation(requestModule, result); }
+    static JsErrorCode WINAPI JsModuleEvaluation(JsModuleRecord requestModule, JsValueRef* result) { return HOOK_JS_API(ModuleEvaluation(requestModule, result)); }
     static JsErrorCode WINAPI JsInitializeModuleRecord(JsModuleRecord referencingModule, JsValueRef normalizedSpecifier, JsModuleRecord* moduleRecord) {
-        return m_jsApiHooks.pfJsrtInitializeModuleRecord(referencingModule, normalizedSpecifier, moduleRecord);
+        return HOOK_JS_API(InitializeModuleRecord(referencingModule, normalizedSpecifier, moduleRecord));
     }
-    static JsErrorCode WINAPI JsSetModuleHostInfo(JsModuleRecord requestModule, JsModuleHostInfoKind moduleHostInfo, void* hostInfo) { return m_jsApiHooks.pfJsrtSetModuleHostInfo(requestModule, moduleHostInfo, hostInfo); }
-    static JsErrorCode WINAPI JsGetModuleHostInfo(JsModuleRecord requestModule, JsModuleHostInfoKind moduleHostInfo, void** hostInfo) { return m_jsApiHooks.pfJsrtGetModuleHostInfo(requestModule, moduleHostInfo, hostInfo); }
+    static JsErrorCode WINAPI JsSetModuleHostInfo(JsModuleRecord requestModule, JsModuleHostInfoKind moduleHostInfo, void* hostInfo) { return HOOK_JS_API(SetModuleHostInfo(requestModule, moduleHostInfo, hostInfo)); }
+    static JsErrorCode WINAPI JsGetModuleHostInfo(JsModuleRecord requestModule, JsModuleHostInfoKind moduleHostInfo, void** hostInfo) { return HOOK_JS_API(GetModuleHostInfo(requestModule, moduleHostInfo, hostInfo)); }
 
     static JsErrorCode WINAPI JsTTDCreateRecordRuntime(JsRuntimeAttributes attributes, const byte* infoUri, size_t infoUriCount, size_t snapInterval, size_t snapHistoryLength, JsTTDInitializeForWriteLogStreamCallback writeInitializeFunction, TTDOpenResourceStreamCallback openResourceStream, JsTTDReadBytesFromStreamCallback readBytesFromStream, JsTTDWriteBytesToStreamCallback writeBytesToStream, JsTTDFlushAndCloseStreamCallback flushAndCloseStream, JsThreadServiceCallback threadService, JsRuntimeHandle *runtime) {  return HOOK_JS_API(TTDCreateRecordRuntime(attributes, infoUri, infoUriCount, snapInterval, snapHistoryLength, writeInitializeFunction, openResourceStream, readBytesFromStream, writeBytesToStream, flushAndCloseStream, threadService, runtime)); }
     static JsErrorCode WINAPI JsTTDCreateReplayRuntime(JsRuntimeAttributes attributes, const byte* infoUri, size_t infoUriCount, JsTTDInitializeForWriteLogStreamCallback writeInitializeFunction, TTDOpenResourceStreamCallback openResourceStream, JsTTDReadBytesFromStreamCallback readBytesFromStream, JsTTDWriteBytesToStreamCallback writeBytesToStream, JsTTDFlushAndCloseStreamCallback flushAndCloseStream, JsThreadServiceCallback threadService, JsRuntimeHandle *runtime) { return HOOK_JS_API(TTDCreateReplayRuntime(attributes, infoUri, infoUriCount, false, writeInitializeFunction, openResourceStream, readBytesFromStream, writeBytesToStream, flushAndCloseStream, threadService, runtime)); }

+ 1 - 0
lib/Jsrt/Core/CMakeLists.txt

@@ -1,5 +1,6 @@
 add_library (Chakra.Jsrt.Core OBJECT
     JsrtContextCore.cpp
+    JsrtCore.cpp
     )
 
 target_include_directories (

+ 5 - 5
lib/Jsrt/Core/JsrtCore.cpp

@@ -6,7 +6,7 @@
 #include "JsrtInternal.h"
 #include "jsrtHelper.h"
 #include "JsrtContextCore.h"
-#include "chakracore.h"
+#include "ChakraCore.h"
 
 CHAKRA_API
 JsInitializeModuleRecord(
@@ -160,10 +160,10 @@ JsSetModuleHostInfo(
             moduleRecord->SetHostDefined(hostInfo);
             break;
         case JsModuleHostInfo_FetchImportedModuleCallback:
-            currentContext->GetHostScriptContext()->SetFetchImportedModuleCallback(static_cast<FetchImportedModuleCallBack>(hostInfo));
+            currentContext->GetHostScriptContext()->SetFetchImportedModuleCallback(reinterpret_cast<FetchImportedModuleCallBack>(hostInfo));
             break;
         case JsModuleHostInfo_NotifyModuleReadyCallback:
-            currentContext->GetHostScriptContext()->SetNotifyModuleReadyCallback(static_cast<NotifyModuleReadyCallback>(hostInfo));
+            currentContext->GetHostScriptContext()->SetNotifyModuleReadyCallback(reinterpret_cast<NotifyModuleReadyCallback>(hostInfo));
             break;
         default:
             return JsInvalidModuleHostInfoKind;
@@ -201,10 +201,10 @@ JsGetModuleHostInfo(
             *hostInfo = moduleRecord->GetHostDefined();
             break;
         case JsModuleHostInfo_FetchImportedModuleCallback:
-            *hostInfo = currentContext->GetHostScriptContext()->GetFetchImportedModuleCallback();
+            *hostInfo = reinterpret_cast<void*>(currentContext->GetHostScriptContext()->GetFetchImportedModuleCallback());
             break;
         case JsModuleHostInfo_NotifyModuleReadyCallback:
-            *hostInfo = currentContext->GetHostScriptContext()->GetNotifyModuleReadyCallback();
+            *hostInfo = reinterpret_cast<void*>(currentContext->GetHostScriptContext()->GetNotifyModuleReadyCallback());
             break;
         default:
             return JsInvalidModuleHostInfoKind;

+ 10 - 10
lib/Parser/Parse.cpp

@@ -329,7 +329,7 @@ HRESULT Parser::ParseSourceInternal(
     AssertMem(parseTree);
     AssertPsz(pszSrc);
     AssertMemN(pse);
-   
+
     if (this->IsBackgroundParser())
     {
         PROBE_STACK_NO_DISPOSE(m_scriptContext, Js::Constants::MinStackDefault);
@@ -444,7 +444,7 @@ HRESULT Parser::ParseSourceInternal(
     m_scriptContext->ProfileEnd(Js::ParsePhase);
 #endif
     JS_ETW_INTERNAL(EventWriteJSCRIPT_PARSE_STOP(m_scriptContext, 0));
-    
+
     return hr;
 }
 
@@ -820,7 +820,7 @@ Symbol* Parser::AddDeclForPid(ParseNodePtr pnode, IdentPtr pid, SymbolType symbo
         Assert(this->m_reparsingLambdaParams);
         refForDecl->funcId = GetCurrentFunctionNode()->sxFnc.functionId;
     }
-    
+
     if (blockInfo == GetCurrentBlockInfo())
     {
         refForUse = refForDecl;
@@ -1695,7 +1695,7 @@ void Parser::BindPidRefsInScope(IdentPtr pid, Symbol *sym, int blockId, uint max
             sym->PromoteAssignmentState();
             if (m_currentNodeFunc && sym->GetIsFormal())
             {
-                m_currentNodeFunc->sxFnc.SetHasAnyWriteToFormals(true);                
+                m_currentNodeFunc->sxFnc.SetHasAnyWriteToFormals(true);
             }
         }
 
@@ -1712,7 +1712,7 @@ void Parser::BindPidRefsInScope(IdentPtr pid, Symbol *sym, int blockId, uint max
 
         if (m_currentNodeFunc && ref->isEscape && sym->GetSymbolType() == STFunction)
         {
-            if (m_sourceContextInfo ? 
+            if (m_sourceContextInfo ?
                     !PHASE_OFF_RAW(Js::DisableStackFuncOnDeferredEscapePhase, m_sourceContextInfo->sourceContextId, m_currentNodeFunc->sxFnc.functionId) :
                     !PHASE_OFF1(Js::DisableStackFuncOnDeferredEscapePhase))
             {
@@ -1751,7 +1751,7 @@ void Parser::MarkEscapingRef(ParseNodePtr pnode, IdentToken *pToken)
 
 void Parser::SetNestedFuncEscapes() const
 {
-    if (m_sourceContextInfo ? 
+    if (m_sourceContextInfo ?
             !PHASE_OFF_RAW(Js::DisableStackFuncOnDeferredEscapePhase, m_sourceContextInfo->sourceContextId, m_currentNodeFunc->sxFnc.functionId) :
             !PHASE_OFF1(Js::DisableStackFuncOnDeferredEscapePhase))
     {
@@ -2110,7 +2110,7 @@ ParseNodePtr Parser::ParseMetaProperty(tokens metaParentKeyword, charcount_t ich
     return nullptr;
 }
 
-template<bool buildAST> 
+template<bool buildAST>
 void Parser::ParseNamedImportOrExportClause(ModuleImportOrExportEntryList* importOrExportEntryList, bool isExportClause)
 {
     Assert(m_token.tk == tkLCurly);
@@ -2597,7 +2597,7 @@ LFunction:
             // Rewind back to the function token and let the helper handle the parsing.
             m_pscan->SeekTo(parsedFunction);
             pnode = ParseFncDecl<buildAST>(flags);
-            
+
             if (buildAST)
             {
                 AnalysisAssert(pnode != nullptr);
@@ -4820,7 +4820,7 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
     RestorePoint beginNameHint;
     m_pscan->Capture(&beginNameHint);
 
-    ParseNodePtr pnodeFncExprScope = nullptr;    
+    ParseNodePtr pnodeFncExprScope = nullptr;
     Scope *fncExprScope = nullptr;
     if (!fDeclaration)
     {
@@ -9500,7 +9500,7 @@ LDefaultTokenFor:
                 pnode->sxForInOrForOf.pnodeLval = pnodeT;
                 pnode->sxForInOrForOf.pnodeObj = pnodeObj;
                 pnode->ichLim = ichLim;
-                
+
                 TrackAssignment<true>(pnodeT, nullptr);
             }
             PushStmt<buildAST>(&stmt, pnode, isForOf ? knopForOf : knopForIn, pnodeLabel, pLabelIdList);

+ 41 - 46
pal/src/cruntime/path.cpp

@@ -1,6 +1,6 @@
 //
 // Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information. 
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 //
 
 /*++
@@ -89,7 +89,7 @@ _wsplitpath(
           dospath?dospath:W16_NULLSTRING, drive, dir, fname, ext);
 
     /* Do performance intensive error checking only in debug builds.
-    
+
     NOTE: This function must fail predictably across all platforms.
     Under Windows this function throw an access violation if NULL
     was passed in as the value for path.
@@ -101,7 +101,7 @@ _wsplitpath(
         ERROR( "path cannot be NULL!\n" );
     }
 #endif
-    
+
     if( lstrlenW( dospath ) >= _MAX_PATH )
     {
         ERROR("Path length is > _MAX_PATH (%d)!\n", _MAX_PATH);
@@ -159,7 +159,7 @@ _wsplitpath(
                   size+1, _MAX_DIR);
             ON_ERROR;
         }
-        
+
         memcpy(dir, path, size*sizeof(WCHAR));
         dir[size] = 0;
 
@@ -200,11 +200,11 @@ _wsplitpath(
         memcpy(ext, period_ptr, size*sizeof(WCHAR));
         ext[size-1] = 0;
     }
-    
+
     TRACE("Path components are '%S' '%S' '%S'\n", dir, fname, ext);
 
 done:
-    
+
     LOGEXIT("_wsplitpath returns.\n");
     PERF_EXIT(_wsplitpath);
 }
@@ -237,23 +237,23 @@ _splitpath(
           path?path:"NULL", drive, dir, fname, ext);
 
    /* Do performance intensive error checking only in debug builds.
-    
+
     NOTE: This function must fail predictably across all platforms.
     Under Windows this function throw an access violation if NULL
     was passed in as the value for path.
-    
+
     */
 #if _DEBUG
     if ( !path )
     {
         ERROR( "path cannot be NULL!\n" );
     }
-    
+
     if( strlen( path ) >= _MAX_PATH )
     {
         ERROR( "Path length is > _MAX_PATH (%d)!\n", _MAX_PATH);
     }
-#endif    
+#endif
 
     /* no drive letters in the PAL */
     if(drive)
@@ -269,7 +269,7 @@ _splitpath(
 
     /* Call up to Unicode version; pass NULL for parameters the caller doesn't
        care about */
-    _wsplitpath(w_path, NULL, dir?w_dir:NULL, 
+    _wsplitpath(w_path, NULL, dir?w_dir:NULL,
 	                fname?w_fname:NULL, ext?w_ext:NULL);
 
     /* Convert result back to MultiByte; report conversion errors but don't
@@ -317,21 +317,21 @@ Function:
 See MSDN doc.
 
 --*/
-void   
-__cdecl 
+void
+__cdecl
 _makepath(
-          char *path, 
-          const char *drive, 
-          const char *dir, 
-          const char *fname, 
+          char *path,
+          const char *drive,
+          const char *dir,
+          const char *fname,
           const char *ext)
 {
     UINT Length = 0;
 
     PERF_ENTRY(_makepath);
-    ENTRY( "_makepath (path=%p, drive=%p (%s), dir=%p (%s), fname=%p (%s), ext=%p (%s))\n", 
-           path, drive ? drive:"NULL", drive ? drive:"NULL", dir ? dir:"NULL", dir ? dir:"NULL", fname ? fname:"NULL", fname ? fname:"NULL", 
-           ext ? ext:"NULL", 
+    ENTRY( "_makepath (path=%p, drive=%p (%s), dir=%p (%s), fname=%p (%s), ext=%p (%s))\n",
+           path, drive ? drive:"NULL", drive ? drive:"NULL", dir ? dir:"NULL", dir ? dir:"NULL", fname ? fname:"NULL", fname ? fname:"NULL",
+           ext ? ext:"NULL",
            ext ? ext:"NULL");
 
     path[ 0 ] = '\0';
@@ -348,7 +348,7 @@ _makepath(
     {
         UINT DirLength = strlen( dir );
         Length += DirLength ;
-        
+
         if ( Length < _MAX_PATH )
         {
             strncat( path, dir, DirLength );
@@ -376,7 +376,7 @@ _makepath(
     {
         UINT fNameLength = strlen( fname );
         Length += fNameLength;
-        
+
         if ( Length < _MAX_PATH )
         {
             strncat( path, fname, fNameLength );
@@ -391,7 +391,7 @@ _makepath(
     {
         UINT ExtLength = strlen( ext );
         Length += ExtLength;
-        
+
         if ( ext[ 0 ] !=  '.' )
         {
             /* Add a '.' */
@@ -412,7 +412,7 @@ _makepath(
             /* Already has a '.' */
             if ( Length < _MAX_PATH )
             {
-                strncat( path, ext, ExtLength );    
+                strncat( path, ext, ExtLength );
             }
             else
             {
@@ -428,7 +428,7 @@ _makepath(
 
 Max_Path_Error:
 
-    ERROR( "path cannot be greater then _MAX_PATH\n" ); 
+    ERROR( "path cannot be greater then _MAX_PATH\n" );
     path[ 0 ] = '\0';
     LOGEXIT( "_makepath returning void \n" );
     PERF_EXIT(_makepath);
@@ -442,20 +442,20 @@ Function:
 See MSDN doc.
 
 --*/
-void   
-__cdecl 
+void
+__cdecl
 _wmakepath(
-          char16_t *path, 
-          const char16_t *drive, 
-          const char16_t *dir, 
-          const char16_t *fname, 
+          char16_t *path,
+          const char16_t *drive,
+          const char16_t *dir,
+          const char16_t *fname,
           const char16_t *ext)
 {
     CHAR Dir[ _MAX_DIR ]={0};
     CHAR FileName[ _MAX_FNAME ]={0};
     CHAR Ext[ _MAX_EXT ]={0};
     CHAR Path[ _MAX_PATH ]={0};
-    
+
     PERF_ENTRY(_wmakepath);
     ENTRY("_wmakepath (path=%p, drive=%p (%S), dir=%p (%S), fname=%p (%S), ext=%p (%S))\n",
           path, drive ? drive:W16_NULLSTRING, drive ? drive:W16_NULLSTRING, dir ? dir:W16_NULLSTRING, dir ? dir:W16_NULLSTRING,
@@ -470,7 +470,7 @@ _wmakepath(
               "support drive letters. drive is being ignored!.\n" );
     }
 
-    if ((dir != NULL) &&  WideCharToMultiByte( CP_ACP, 0, dir, -1, Dir, 
+    if ((dir != NULL) &&  WideCharToMultiByte( CP_ACP, 0, dir, -1, Dir,
                                                _MAX_DIR, NULL, NULL ) == 0 )
     {
         ASSERT( "An error occurred while converting dir to multibyte."
@@ -523,11 +523,11 @@ Function:
 See MSDN doc.
 
 --*/
-char *   
-__cdecl 
+char *
+__cdecl
 _fullpath(
-          char *absPath, 
-          const char *relPath, 
+          char *absPath,
+          const char *relPath,
           size_t maxLength)
 {
     char realpath_buf[PATH_MAX+1];
@@ -540,7 +540,7 @@ _fullpath(
     PERF_ENTRY(_fullpath);
     ENTRY("_fullpath (absPath=%p, relPath=%p (%s), maxLength = %lu)\n",
           absPath, relPath ? relPath:"NULL", relPath ? relPath:"NULL", maxLength);
-    
+
     if (strncpy_s(path_copy, sizeof(path_copy), relPath ? relPath : ".", cPathCopy) != SAFECRT_SUCCESS)
     {
         TRACE("_fullpath: strncpy_s failed!\n");
@@ -551,10 +551,8 @@ _fullpath(
 
     if(NULL == realpath(path_copy, realpath_buf))
     {
-        ERROR("realpath() failed; problem path is '%s'. errno is %d (%s)\n",
-                realpath_buf, errno, strerror(errno));
-        goto fullpathExit;
-    }   
+        // do nothing. filename may not be there yet..
+    }
 
     TRACE("real path is %s\n", realpath_buf);
     min_length = strlen(realpath_buf)+1; // +1 for the NULL terminator
@@ -586,12 +584,9 @@ _fullpath(
 
     strcpy_s(absPath, maxLength, realpath_buf);
     retval = absPath;
-    
+
 fullpathExit:
     LOGEXIT("_fullpath returns char * %p\n", retval);
     PERF_EXIT(_fullpath);
     return retval;
 }
-
-
-

+ 7 - 11
test/es6/rlexe.xml

@@ -1281,46 +1281,43 @@
     <tags>exclude_dynapogo, exclude_xplat</tags>
   </default>
 </test>
-  <test>
+<test>
     <default>
-      <files>moduletest1.js</files>
-      <compile-flags>-ES6Module</compile-flags>
-      <tags>exclude_dynapogo, exclude_xplat</tags>
+        <files>moduletest1.js</files>
+        <compile-flags>-ES6Module</compile-flags>
+        <tags>exclude_dynapogo</tags>
     </default>
-  </test>
+</test>
 <test>
     <default>
         <files>module-syntax.js</files>
         <compile-flags>-ES6Module -args summary -endargs</compile-flags>
-        <tags>exclude_xplat</tags>
+        <tags>exclude_dynapogo</tags>
     </default>
 </test>
 <test>
     <default>
         <files>module-syntax1.js</files>
         <compile-flags>-ES6Module -args summary -endargs</compile-flags>
-        <tags>exclude_xplat</tags>
     </default>
 </test>
 <test>
     <default>
         <files>module-functionality.js</files>
         <compile-flags>-ES6Module -args summary -endargs</compile-flags>
-        <tags>exclude_xplat,exclude_dynapogo</tags>
+        <tags>exclude_dynapogo</tags>
     </default>
 </test>
 <test>
     <default>
         <files>module-syntax.js</files>
         <compile-flags>-ES6Module -force:deferparse -args summary -endargs</compile-flags>
-        <tags>exclude_xplat</tags>
     </default>
 </test>
 <test>
     <default>
         <files>module-syntax1.js</files>
         <compile-flags>-ES6Module -force:deferparse -args summary -endargs</compile-flags>
-        <tags>exclude_xplat</tags>
     </default>
 </test>
 <test>
@@ -1328,7 +1325,6 @@
         <files>module-namespace.js</files>
         <compile-flags>-ES6Module -Es6ToStringTag</compile-flags>
         <baseline>module-namespace.baseline</baseline>
-        <tags>exclude_xplat</tags>
     </default>
 </test>
 <test>