Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: test/promises-aplus/lib/global.js

Issue 196733002: Add Promises/A+ Compliance Test Suite. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/promises-aplus/lib/global.js
diff --git a/test/cctest/print-extension.cc b/test/promises-aplus/lib/global.js
similarity index 68%
copy from test/cctest/print-extension.cc
copy to test/promises-aplus/lib/global.js
index 9f629195bd7909c1a97760484cea37b600461b98..1466d2063b5be2351b49a021578cd1091992fbee 100644
--- a/test/cctest/print-extension.cc
+++ b/test/promises-aplus/lib/global.js
@@ -25,27 +25,52 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include "print-extension.h"
+var global = this.global || {};
+var setTimeout;
+var clearTimeout;
-namespace v8 {
-namespace internal {
+(function() {
+var timers = {};
+var currentId = 0;
-v8::Handle<v8::FunctionTemplate> PrintExtension::GetNativeFunctionTemplate(
- v8::Isolate* isolate,
- v8::Handle<v8::String> str) {
- return v8::FunctionTemplate::New(isolate, PrintExtension::Print);
+function PostMicrotask(fn) {
+ var o = {};
+ Object.observe(o, function() {
+ fn();
+ });
+ // Change something to enqueue a microtask.
+ o.x = 'hello';
}
-
-void PrintExtension::Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
- for (int i = 0; i < args.Length(); i++) {
- if (i != 0) printf(" ");
- v8::HandleScope scope(args.GetIsolate());
- v8::String::Utf8Value str(args[i]);
- if (*str == NULL) return;
- printf("%s", *str);
+setInterval = function(fn, delay) {
+ var i = 0;
+ var id = currentId++;
+ function loop() {
+ if (!timers[id]) {
+ return;
+ }
+ if (i++ >= delay) {
+ fn();
+ }
+ PostMicrotask(loop);
}
- printf("\n");
+ PostMicrotask(loop);
+ timers[id] = true;
+ return id;
+}
+
+clearTimeout = function(id) {
+ delete timers[id];
+}
+
+clearInterval = clearTimeout;
+
+setTimeout = function(fn, delay) {
+ var id = setInterval(function() {
+ fn();
+ clearInterval(id);
+ }, delay);
+ return id;
}
-} } // namespace v8::internal
+}());

Powered by Google App Engine
This is Rietveld 408576698