Index: tools/foozzie/v8_mock.js |
diff --git a/tools/foozzie/v8_mock.js b/tools/foozzie/v8_mock.js |
index 9c314e7f6633f4b9a6046bc161aefab9dff3b390..5217a02666d062a9ad531bac46ec7aa724459afa 100644 |
--- a/tools/foozzie/v8_mock.js |
+++ b/tools/foozzie/v8_mock.js |
@@ -12,57 +12,55 @@ |
// This will be overridden in the test cases. The override can be minimized. |
var __PrettyPrint = function __PrettyPrint(msg) { print(msg); }; |
- |
-// All calls to f.arguments are replaced by f.mock_arguments by an external |
-// script. |
-Object.prototype.mock_arguments = ['x', 'y'] |
Michael Achenbach
2017/01/25 14:25:44
This is unused. The 2-3 test cases that lead to f.
|
- |
- |
// Mock Math.random. |
-var __magic_index_for_mocked_random = 0 |
-Math.random = function(){ |
- __magic_index_for_mocked_random = (__magic_index_for_mocked_random + 1) % 10 |
- return __magic_index_for_mocked_random / 10.0; |
-} |
- |
+(function () { |
+ var index = 0 |
Michael Achenbach
2017/01/25 14:25:44
I shortened all these cryptic variable names.
|
+ Math.random = function() { |
+ index = (index + 1) % 10; |
+ return index / 10.0; |
+ } |
+})(); |
// Mock Date. |
-var __magic_index_for_mocked_date = 0 |
-var __magic_mocked_date = 1477662728696 |
-__magic_mocked_date_now = function(){ |
- __magic_index_for_mocked_date = (__magic_index_for_mocked_date + 1) % 10 |
- __magic_mocked_date = __magic_mocked_date + __magic_index_for_mocked_date + 1 |
- return __magic_mocked_date |
-} |
+(function () { |
+ var index = 0 |
+ var mockDate = 1477662728696 |
+ var mockDateNow = function() { |
+ index = (index + 1) % 10 |
+ mockDate = mockDate + index + 1 |
+ return mockDate |
+ } |
-var __original_date = Date; |
-__magic_mock_date_handler = { |
- construct: function(target, args, newTarget) { |
- if (args.length > 0) { |
- return new (Function.prototype.bind.apply(__original_date, [null].concat(args))); |
- } else { |
- return new __original_date(__magic_mocked_date_now()); |
- } |
- }, |
- get: function(target, property, receiver) { |
- if (property == "now") { |
- return __magic_mocked_date_now; |
- } |
- }, |
-} |
+ var origDate = Date; |
+ var handler = { |
+ construct: function(target, args, newTarget) { |
+ if (args.length > 0) { |
+ return new ( |
+ Function.prototype.bind.apply(origDate, [null].concat(args))); |
+ } else { |
+ return new origDate(mockDateNow()); |
+ } |
+ }, |
+ get: function(target, property, receiver) { |
+ if (property == "now") { |
+ return mockDateNow; |
+ } |
+ }, |
+ } |
-Date = new Proxy(Date, __magic_mock_date_handler); |
+ Date = new Proxy(Date, handler); |
+})(); |
// Mock stack traces. |
Error.prepareStackTrace = function (error, structuredStackTrace) { |
return ""; |
-} |
+}; |
// Mock buffer access in float typed arrays because of varying NaN patterns. |
// Note, for now we just use noop forwarding proxies, because they already |
// turn off optimizations. |
function __MockTypedArray(arrayType) { |
- array_creation_handler = { |
+ var array_creation_handler = { |
construct: function(target, args) { |
return new Proxy(new arrayType(args), {}); |
}, |
@@ -74,23 +72,25 @@ Float32Array = __MockTypedArray(Float32Array); |
Float64Array = __MockTypedArray(Float64Array); |
// Mock Worker. |
-var __magic_index_for_mocked_worker = 0 |
-// TODO(machenbach): Randomize this for each test case, but keep stable during |
-// comparison. Also data and random above. |
-var __magic_mocked_worker_messages = [ |
- undefined, 0, -1, "", "foo", 42, [], {}, [0], {"x": 0} |
-] |
-Worker = function(code){ |
- try { |
- __PrettyPrint(eval(code)); |
- } catch(e) { |
- __PrettyPrint(e); |
- } |
- this.getMessage = function(){ |
- __magic_index_for_mocked_worker = (__magic_index_for_mocked_worker + 1) % 10 |
- return __magic_mocked_worker_messages[__magic_index_for_mocked_worker]; |
- } |
- this.postMessage = function(msg){ |
- __PrettyPrint(msg); |
- } |
-} |
+(function () { |
+ var index = 0; |
+ // TODO(machenbach): Randomize this for each test case, but keep stable |
+ // during comparison. Also data and random above. |
+ var workerMessages = [ |
+ undefined, 0, -1, "", "foo", 42, [], {}, [0], {"x": 0} |
+ ]; |
+ Worker = function(code){ |
+ try { |
+ __PrettyPrint(eval(code)); |
+ } catch(e) { |
+ __PrettyPrint(e); |
+ } |
+ this.getMessage = function(){ |
+ index = (index + 1) % 10; |
+ return workerMessages[index]; |
+ } |
+ this.postMessage = function(msg){ |
+ __PrettyPrint(msg); |
+ } |
+ }; |
+})(); |