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 |
+}()); |