Bläddra i källkod

262: fix test file and enable testing on xplat

Oguz Bastemur 8 år sedan
förälder
incheckning
2cc2f022ff
6 ändrade filer med 41 tillägg och 37 borttagningar
  1. 4 6
      bin/ch/262.js
  2. 1 1
      bin/ch/HostConfigFlagsList.h
  3. 12 11
      bin/ch/WScriptJsrt.cpp
  4. 21 15
      test/262/262test.js
  5. 2 3
      test/262/rlexe.xml
  6. 1 1
      test/rlexedirs.xml

+ 4 - 6
bin/ch/262.js

@@ -3,8 +3,7 @@
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 //-------------------------------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------------------------------
 
 
-LR"====(
-
+R"====(
 var $262 = {
 var $262 = {
   createRealm: function () {
   createRealm: function () {
     return WScript.LoadScript('', 'samethread').$262;
     return WScript.LoadScript('', 'samethread').$262;
@@ -12,7 +11,7 @@ var $262 = {
   global: this,
   global: this,
   agent: {
   agent: {
     start: function (src) {
     start: function (src) {
-      WScript.LoadScript(        
+      WScript.LoadScript(
         `
         `
         $262 = {
         $262 = {
           agent:{
           agent:{
@@ -28,6 +27,5 @@ var $262 = {
     sleep: function (timeout) { WScript.Sleep(timeout); },
     sleep: function (timeout) { WScript.Sleep(timeout); },
     getReport: function () { return WScript.GetReport(); },
     getReport: function () { return WScript.GetReport(); },
   },
   },
-}
-
-)===="
+};
+)===="

+ 1 - 1
bin/ch/HostConfigFlagsList.h

@@ -14,6 +14,6 @@ FLAG(bool, EnsureCloseJITServer,            "JIT process will be force closed wh
 FLAG(bool, IgnoreScriptErrorCode,           "Don't return error code on script error", false)
 FLAG(bool, IgnoreScriptErrorCode,           "Don't return error code on script error", false)
 FLAG(bool, MuteHostErrorMsg,                "Mute host error output, e.g. module load failures", false)
 FLAG(bool, MuteHostErrorMsg,                "Mute host error output, e.g. module load failures", false)
 FLAG(bool, TraceHostCallback,               "Output traces for host callbacks", false)
 FLAG(bool, TraceHostCallback,               "Output traces for host callbacks", false)
-FLAG(bool, $262,                            "load $262 harness", false)
+FLAG(bool, Test262,                         "load Test262 harness", false)
 #undef FLAG
 #undef FLAG
 #endif
 #endif

+ 12 - 11
bin/ch/WScriptJsrt.cpp

@@ -938,7 +938,10 @@ bool WScriptJsrt::Initialize()
 
 
     IfJsrtErrorFail(InitializeModuleCallbacks(), false);
     IfJsrtErrorFail(InitializeModuleCallbacks(), false);
 
 
-    if (HostConfigFlags::flags.$262)
+    // When the command-line argument `-Test262` is set,
+    // WScript will have the extra support API below and $262 will be
+    // added to global scope
+    if (HostConfigFlags::flags.Test262)
     {
     {
         IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Broadcast", BroadcastCallback));
         IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Broadcast", BroadcastCallback));
         IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "ReceiveBroadcast", ReceiveBroadcastCallback));
         IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "ReceiveBroadcast", ReceiveBroadcastCallback));
@@ -947,19 +950,17 @@ bool WScriptJsrt::Initialize()
         IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Leaving", LeavingCallback));
         IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Leaving", LeavingCallback));
         IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Sleep", SleepCallback));
         IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Sleep", SleepCallback));
 
 
-
-        // OSX does build does not support $262 as filename
-        const wchar_t $262[] =
+        // $262
+        const char Test262[] =
             #include "262.js"
             #include "262.js"
-            ;
+        ;
 
 
-        JsValueRef $262ScriptRef;
-        IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateStringUtf16((uint16_t*)$262, _countof($262) - 1, &$262ScriptRef));
+        JsValueRef Test262ScriptRef;
+        IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateString(Test262, strlen(Test262), &Test262ScriptRef));
 
 
         JsValueRef fname;
         JsValueRef fname;
-        IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateString("$262", strlen("$262"), &fname));
-        IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsRun($262ScriptRef, WScriptJsrt::GetNextSourceContext(), fname, JsParseScriptAttributeNone, nullptr));
-
+        IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateString("262", strlen("262"), &fname));
+        IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsRun(Test262ScriptRef, WScriptJsrt::GetNextSourceContext(), fname, JsParseScriptAttributeNone, nullptr));
     }
     }
 
 
 Error:
 Error:
@@ -1534,7 +1535,7 @@ HRESULT WScriptJsrt::ModuleMessage::Call(LPCSTR fileName)
                     specifierFullPath = moduleDirEntry->second;
                     specifierFullPath = moduleDirEntry->second;
                 }
                 }
             }
             }
-            
+
             specifierFullPath += *specifierStr;
             specifierFullPath += *specifierStr;
             if (_fullpath(fullPath, specifierFullPath.c_str(), _MAX_PATH) == nullptr)
             if (_fullpath(fullPath, specifierFullPath.c_str(), _MAX_PATH) == nullptr)
             {
             {

+ 21 - 15
test/$262/$262test.js → test/262/262test.js

@@ -1,3 +1,8 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
 "use strict";
 "use strict";
 var $ = {  global: this,  createRealm(options) {    options = options || {};    options.globals = options.globals || {};    var realm = WScript.LoadScript(this.source, 'samethread');    realm.$.source = this.source;    realm.$.destroy = function () {      if (options.destroy) {        options.destroy();      }    };    for(var glob in options.globals) {      realm.$.global[glob] = options.globals[glob];    }    return realm.$;  },  evalScript(code) {    try {      WScript.LoadScript(code);      return { type: 'normal', value: undefined };    } catch (e) {      return { type: 'throw', value: e };    }  },  getGlobal(name) {    return this.global[name];  },  setGlobal(name, value) {    this.global[name] = value;  },  destroy() { /* noop */ },  source: "var $ = {  global: this,  createRealm(options) {    options = options || {};    options.globals = options.globals || {};    var realm = WScript.LoadScript(this.source, 'samethread');    realm.$.source = this.source;    realm.$.destroy = function () {      if (options.destroy) {        options.destroy();      }    };    for(var glob in options.globals) {      realm.$.global[glob] = options.globals[glob];    }    return realm.$;  },  evalScript(code) {    try {      WScript.LoadScript(code);      return { type: 'normal', value: undefined };    } catch (e) {      return { type: 'throw', value: e };    }  },  getGlobal(name) {    return this.global[name];  },  setGlobal(name, value) {    this.global[name] = value;  },  destroy() { /* noop */ },  source: \"\"};"};function Test262Error(message) {
 var $ = {  global: this,  createRealm(options) {    options = options || {};    options.globals = options.globals || {};    var realm = WScript.LoadScript(this.source, 'samethread');    realm.$.source = this.source;    realm.$.destroy = function () {      if (options.destroy) {        options.destroy();      }    };    for(var glob in options.globals) {      realm.$.global[glob] = options.globals[glob];    }    return realm.$;  },  evalScript(code) {    try {      WScript.LoadScript(code);      return { type: 'normal', value: undefined };    } catch (e) {      return { type: 'throw', value: e };    }  },  getGlobal(name) {    return this.global[name];  },  setGlobal(name, value) {    this.global[name] = value;  },  destroy() { /* noop */ },  source: "var $ = {  global: this,  createRealm(options) {    options = options || {};    options.globals = options.globals || {};    var realm = WScript.LoadScript(this.source, 'samethread');    realm.$.source = this.source;    realm.$.destroy = function () {      if (options.destroy) {        options.destroy();      }    };    for(var glob in options.globals) {      realm.$.global[glob] = options.globals[glob];    }    return realm.$;  },  evalScript(code) {    try {      WScript.LoadScript(code);      return { type: 'normal', value: undefined };    } catch (e) {      return { type: 'throw', value: e };    }  },  getGlobal(name) {    return this.global[name];  },  setGlobal(name, value) {    this.global[name] = value;  },  destroy() { /* noop */ },  source: \"\"};"};function Test262Error(message) {
     if (message) this.message = message;
     if (message) this.message = message;
@@ -21,7 +26,7 @@ function $DONE(err) {
   if (err) {
   if (err) {
     $ERROR(err);
     $ERROR(err);
   }
   }
-  print('pass');
+  print('PASS');
   $.destroy();
   $.destroy();
 }
 }
 
 
@@ -29,7 +34,6 @@ function $LOG(str) {
   print(str);
   print(str);
 }
 }
 
 
-
 function assert(mustBeTrue, message) {
 function assert(mustBeTrue, message) {
   if (mustBeTrue === true) {
   if (mustBeTrue === true) {
     return;
     return;
@@ -124,31 +128,35 @@ assert.throws.early = function(err, code) {
 // them go into a wait, thus controlling the waiting order.  Then we wake them
 // them go into a wait, thus controlling the waiting order.  Then we wake them
 // one by one and observe the wakeup order.
 // one by one and observe the wakeup order.
 
 
-for ( var i=0 ; i < 3 ; i++ ) {
+for (var i = 0; i < 3; i++) {
 $262.agent.start(
 $262.agent.start(
 `
 `
 $262.agent.receiveBroadcast(function (sab) {
 $262.agent.receiveBroadcast(function (sab) {
   var ia = new Int32Array(sab);
   var ia = new Int32Array(sab);
-  while (Atomics.load(ia, ${i+1}) == 0);
-  $262.agent.report(${i} + Atomics.wait(ia, 0, 0));
+
+  while (Atomics.load(ia, ${i}) == 0);
+
+  // the one below should produce 'not-equal'.
+  // because ia[i] is no longer 0! (see the loop above)
+  // otherwise it would wait until timeout
+  $262.agent.report(${i} + Atomics.wait(ia, ${i}, 0));
   $262.agent.leaving();
   $262.agent.leaving();
 })
 })
 `);
 `);
 }
 }
 
 
-var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT*4));
+var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 3));
 $262.agent.broadcast(ia.buffer);
 $262.agent.broadcast(ia.buffer);
 
 
-// Make them sleep in order 0 1 2 on ia[0]
-for ( var i=0 ; i < 3 ; i++ ) {
-  Atomics.store(ia, i+1, 1);
+// the `while` loop above waits until we store a value below
+for (var i = 0; i < 3; i++) {
+  Atomics.store(ia, i, 1);
   $262.agent.sleep(500);
   $262.agent.sleep(500);
 }
 }
 
 
-// Wake them up one at a time and check the order is 0 1 2
-for ( var i=0 ; i < 3 ; i++ ) {
-  assert.sameValue(Atomics.wake(ia, 0, 1), 1);
-  assert.sameValue(getReport(), i + "ok");
+for (var i = 0; i < 3; i++) {
+  assert.sameValue(Atomics.load(ia, i), 1);
+  assert.sameValue(getReport(), i + "not-equal");
 }
 }
 
 
 function getReport() {
 function getReport() {
@@ -158,7 +166,5 @@ function getReport() {
     return r;
     return r;
 }
 }
 
 
-
-
 ;$DONE();
 ;$DONE();
 ;$.destroy();
 ;$.destroy();

+ 2 - 3
test/$262/rlexe.xml → test/262/rlexe.xml

@@ -2,9 +2,8 @@
 <regress-exe>
 <regress-exe>
   <test>
   <test>
     <default>
     <default>
-      <compile-flags>-$262</compile-flags>
-      <tags>exclude_xplat</tags>
-      <files>$262test.js</files>
+      <compile-flags>-Test262</compile-flags>
+      <files>262test.js</files>
     </default>
     </default>
   </test>
   </test>
 </regress-exe>
 </regress-exe>

+ 1 - 1
test/rlexedirs.xml

@@ -7,7 +7,7 @@
 </dir>
 </dir>
 <dir>
 <dir>
   <default>
   <default>
-    <files>$262</files>
+    <files>262</files>
   </default>
   </default>
 </dir>
 </dir>
 <dir>
 <dir>