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

Side by Side Diff: test/cctest/compiler/test-run-variables.cc

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "src/v8.h"
6
7 #include "test/cctest/compiler/function-tester.h"
8
9 using namespace v8::internal;
10 using namespace v8::internal::compiler;
11
12 static const char* throws = NULL;
13
14 static const char* load_tests[] = {
15 "var x = a; r = x", "123", "0",
16 "var x = (r = x)", "undefined", "undefined",
17 "var x = (a?1:2); r = x", "1", "2",
18 "const x = a; r = x", "123", "0",
19 "const x = (r = x)", "undefined", "undefined",
20 "const x = (a?3:4); r = x", "3", "4",
21 "'use strict'; const x = a; r = x", "123", "0",
22 "'use strict'; const x = (r = x)", throws, throws,
23 "'use strict'; const x = (a?5:6); r = x", "5", "6",
24 "'use strict'; let x = a; r = x", "123", "0",
25 "'use strict'; let x = (r = x)", throws, throws,
26 "'use strict'; let x = (a?7:8); r = x", "7", "8",
27 NULL
28 };
29
30 static const char* store_tests[] = {
31 "var x = 1; x = a; r = x", "123", "0",
32 "var x = (a?(x=4,2):3); r = x", "2", "3",
33 "var x = (a?4:5); x = a; r = x", "123", "0",
34 "const x = 1; x = a; r = x", "1", "1",
35 "const x = (a?(x=4,2):3); r = x", "2", "3",
36 "const x = (a?4:5); x = a; r = x", "4", "5",
37 // Assignments to 'const' are SyntaxErrors, handled by the parser,
38 // hence we cannot test them here because they are early errors.
39 "'use strict'; let x = 1; x = a; r = x", "123", "0",
40 "'use strict'; let x = (a?(x=4,2):3); r = x", throws, "3",
41 "'use strict'; let x = (a?4:5); x = a; r = x", "123", "0",
42 NULL
43 };
44
45 static const char* bind_tests[] = {
46 "if (a) { const x = a }; r = x;", "123", "undefined",
47 "for (; a > 0; a--) { const x = a }; r = x", "123", "undefined",
48 // Re-initialization of variables other than legacy 'const' is not
49 // possible due to sane variable scoping, hence no tests here.
50 NULL
51 };
52
53
54 static void RunVariableTests(const char* source, const char* tests[]) {
55 FLAG_harmony_scoping = true;
56 EmbeddedVector<char, 512> buffer;
57
58 for (int i = 0; tests[i] != NULL; i += 3) {
59 SNPrintF(buffer, source, tests[i]);
60 PrintF("#%d: %s\n", i / 3, buffer.start());
61 FunctionTester T(buffer.start());
62
63 // Check function with non-falsey parameter.
64 if (tests[i + 1] != throws) {
65 Handle<Object> r = v8::Utils::OpenHandle(*CompileRun(tests[i + 1]));
66 T.CheckCall(r, T.Val(123), T.Val("result"));
67 } else {
68 T.CheckThrows(T.Val(123), T.Val("result"));
69 }
70
71 // Check function with falsey parameter.
72 if (tests[i + 2] != throws) {
73 Handle<Object> r = v8::Utils::OpenHandle(*CompileRun(tests[i + 2]));
74 T.CheckCall(r, T.Val(0.0), T.Val("result"));
75 } else {
76 T.CheckThrows(T.Val(0.0), T.Val("result"));
77 }
78 }
79 }
80
81
82 TEST(StackLoadVariables) {
83 const char* source = "(function(a,r) { %s; return r; })";
84 RunVariableTests(source, load_tests);
85 }
86
87
88 TEST(ContextLoadVariables) {
89 const char* source = "(function(a,r) { %s; function f() {x} return r; })";
90 RunVariableTests(source, load_tests);
91 }
92
93
94 TEST(StackStoreVariables) {
95 const char* source = "(function(a,r) { %s; return r; })";
96 RunVariableTests(source, store_tests);
97 }
98
99
100 TEST(ContextStoreVariables) {
101 const char* source = "(function(a,r) { %s; function f() {x} return r; })";
102 RunVariableTests(source, store_tests);
103 }
104
105
106 TEST(StackInitializeVariables) {
107 const char* source = "(function(a,r) { %s; return r; })";
108 RunVariableTests(source, bind_tests);
109 }
110
111
112 TEST(ContextInitializeVariables) {
113 const char* source = "(function(a,r) { %s; function f() {x} return r; })";
114 RunVariableTests(source, bind_tests);
115 }
116
117
118 TEST(SelfReferenceVariable) {
119 FunctionTester T("(function self() { return self; })");
120
121 T.CheckCall(T.function);
122 CompileRun("var self = 'not a function'");
123 T.CheckCall(T.function);
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698