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

Side by Side Diff: tools/foozzie/v8_mock.js

Issue 2578503003: [foozzie] Initial correctness fuzzer harness. (Closed)
Patch Set: Presubmit Created 4 years 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 unified diff | Download patch
« no previous file with comments | « tools/foozzie/v8_foozzie_test.py ('k') | tools/foozzie/v8_suppressions.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This is intended for permanent JS behavior changes for mocking out
6 // non-deterministic behavior. For temporary suppressions, please refer to
7 // v8_suppressions.js.
8 // This file is loaded before each correctness test cases and won't get
9 // minimized.
10
11
12 // This will be overridden in the test cases. The override can be minimized.
13 var __PrettyPrint = function __PrettyPrint(msg) { print(msg); };
14
15
16 // All calls to f.arguments are replaced by f.mock_arguments by an external
17 // script.
18 Object.prototype.mock_arguments = ['x', 'y']
19
20
21 // Mock Math.random.
22 var __magic_index_for_mocked_random = 0
23 Math.random = function(){
24 __magic_index_for_mocked_random = (__magic_index_for_mocked_random + 1) % 10
25 return __magic_index_for_mocked_random / 10.0;
26 }
27
28
29 // Mock Date.
30 var __magic_index_for_mocked_date = 0
31 var __magic_mocked_date = 1477662728696
32 __magic_mocked_date_now = function(){
33 __magic_index_for_mocked_date = (__magic_index_for_mocked_date + 1) % 10
34 __magic_mocked_date = __magic_mocked_date + __magic_index_for_mocked_date + 1
35 return __magic_mocked_date
36 }
37
38 var __original_date = Date;
39 __magic_mock_date_handler = {
40 construct: function(target, args, newTarget) {
41 if (args.length > 0) {
42 return new (Function.prototype.bind.apply(__original_date, [null].concat(a rgs)));
43 } else {
44 return new __original_date(__magic_mocked_date_now());
45 }
46 },
47 get: function(target, property, receiver) {
48 if (property == "now") {
49 return __magic_mocked_date_now;
50 }
51 },
52 }
53
54 Date = new Proxy(Date, __magic_mock_date_handler);
55
56 // Mock Worker.
57 var __magic_index_for_mocked_worker = 0
58 // TODO(machenbach): Randomize this for each test case, but keep stable during
59 // comparison. Also data and random above.
60 var __magic_mocked_worker_messages = [
61 undefined, 0, -1, "", "foo", 42, [], {}, [0], {"x": 0}
62 ]
63 Worker = function(code){
64 try {
65 __PrettyPrint(eval(code));
66 } catch(e) {
67 __PrettyPrint(e);
68 }
69 this.getMessage = function(){
70 __magic_index_for_mocked_worker = (__magic_index_for_mocked_worker + 1) % 10
71 return __magic_mocked_worker_messages[__magic_index_for_mocked_worker];
72 }
73 this.postMessage = function(msg){
74 __PrettyPrint(msg);
75 }
76 }
OLDNEW
« no previous file with comments | « tools/foozzie/v8_foozzie_test.py ('k') | tools/foozzie/v8_suppressions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698