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

Side by Side Diff: test/cctest/interpreter/test-interpreter-intrinsics.cc

Issue 2034493002: [Interpreter] Add intrinsics for Is<Type> calls. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add non-smi int to test Created 4 years, 6 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
« no previous file with comments | « src/interpreter/interpreter-intrinsics.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/interpreter/interpreter-intrinsics.h" 7 #include "src/interpreter/interpreter-intrinsics.h"
8 #include "test/cctest/interpreter/interpreter-tester.h" 8 #include "test/cctest/interpreter/interpreter-tester.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 CHECK_EQ(*factory->true_value(), *helper.Invoke(helper.NewObject("([1])"))); 84 CHECK_EQ(*factory->true_value(), *helper.Invoke(helper.NewObject("([1])")));
85 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("({})"))); 85 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("({})")));
86 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("(/x/)"))); 86 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("(/x/)")));
87 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Undefined())); 87 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Undefined()));
88 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Null())); 88 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Null()));
89 CHECK_EQ(*factory->false_value(), 89 CHECK_EQ(*factory->false_value(),
90 *helper.Invoke(helper.NewObject("'string'"))); 90 *helper.Invoke(helper.NewObject("'string'")));
91 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("42"))); 91 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("42")));
92 } 92 }
93 93
94 TEST(IsJSProxy) {
95 HandleAndZoneScope handles;
96
97 InvokeIntrinsicHelper helper(handles.main_isolate(), handles.main_zone(),
98 Runtime::kInlineIsJSProxy);
99 Factory* factory = handles.main_isolate()->factory();
100
101 CHECK_EQ(*factory->false_value(),
102 *helper.Invoke(helper.NewObject("new Date()")));
103 CHECK_EQ(*factory->false_value(),
104 *helper.Invoke(helper.NewObject("(function() {})")));
105 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("([1])")));
106 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("({})")));
107 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("(/x/)")));
108 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Undefined()));
109 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Null()));
110 CHECK_EQ(*factory->false_value(),
111 *helper.Invoke(helper.NewObject("'string'")));
112 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("42")));
113 CHECK_EQ(*factory->true_value(),
114 *helper.Invoke(helper.NewObject("new Proxy({},{})")));
115 }
116
117 TEST(IsRegExp) {
118 HandleAndZoneScope handles;
119
120 InvokeIntrinsicHelper helper(handles.main_isolate(), handles.main_zone(),
121 Runtime::kInlineIsRegExp);
122 Factory* factory = handles.main_isolate()->factory();
123
124 CHECK_EQ(*factory->false_value(),
125 *helper.Invoke(helper.NewObject("new Date()")));
126 CHECK_EQ(*factory->false_value(),
127 *helper.Invoke(helper.NewObject("(function() {})")));
128 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("([1])")));
129 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("({})")));
130 CHECK_EQ(*factory->true_value(), *helper.Invoke(helper.NewObject("(/x/)")));
131 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Undefined()));
132 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Null()));
133 CHECK_EQ(*factory->false_value(),
134 *helper.Invoke(helper.NewObject("'string'")));
135 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("42")));
136 }
137
138 TEST(IsTypedArray) {
139 HandleAndZoneScope handles;
140
141 InvokeIntrinsicHelper helper(handles.main_isolate(), handles.main_zone(),
142 Runtime::kInlineIsTypedArray);
143 Factory* factory = handles.main_isolate()->factory();
144
145 CHECK_EQ(*factory->false_value(),
146 *helper.Invoke(helper.NewObject("new Date()")));
147 CHECK_EQ(*factory->false_value(),
148 *helper.Invoke(helper.NewObject("(function() {})")));
149 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("([1])")));
150 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("({})")));
151 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("(/x/)")));
152 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Undefined()));
153 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Null()));
154 CHECK_EQ(*factory->false_value(),
155 *helper.Invoke(helper.NewObject("'string'")));
156 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("42")));
157
158 CHECK_EQ(
159 *factory->true_value(),
160 *helper.Invoke(helper.NewObject("new Uint8Array(new ArrayBuffer(1));")));
161 CHECK_EQ(
162 *factory->true_value(),
163 *helper.Invoke(helper.NewObject("new Uint16Array(new ArrayBuffer(2));")));
164 CHECK_EQ(
165 *factory->true_value(),
166 *helper.Invoke(helper.NewObject("new Int32Array(new ArrayBuffer(4));")));
167 }
168
169 TEST(IsSmi) {
170 HandleAndZoneScope handles;
171
172 InvokeIntrinsicHelper helper(handles.main_isolate(), handles.main_zone(),
173 Runtime::kInlineIsSmi);
174 Factory* factory = handles.main_isolate()->factory();
175
176 CHECK_EQ(*factory->false_value(),
177 *helper.Invoke(helper.NewObject("new Date()")));
178 CHECK_EQ(*factory->false_value(),
179 *helper.Invoke(helper.NewObject("(function() {})")));
180 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("([1])")));
181 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("({})")));
182 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("(/x/)")));
183 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Undefined()));
184 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.Null()));
185 CHECK_EQ(*factory->false_value(),
186 *helper.Invoke(helper.NewObject("'string'")));
187 CHECK_EQ(*factory->false_value(), *helper.Invoke(helper.NewObject("42.2")));
188 CHECK_EQ(*factory->false_value(),
189 *helper.Invoke(helper.NewObject("4294967297")));
190 CHECK_EQ(*factory->true_value(), *helper.Invoke(helper.NewObject("42")));
191 }
192
94 TEST(Call) { 193 TEST(Call) {
95 HandleAndZoneScope handles; 194 HandleAndZoneScope handles;
96 Isolate* isolate = handles.main_isolate(); 195 Isolate* isolate = handles.main_isolate();
97 Factory* factory = isolate->factory(); 196 Factory* factory = isolate->factory();
98 InvokeIntrinsicHelper helper(isolate, handles.main_zone(), 197 InvokeIntrinsicHelper helper(isolate, handles.main_zone(),
99 Runtime::kInlineCall); 198 Runtime::kInlineCall);
100 199
101 CHECK_EQ(Smi::FromInt(20), 200 CHECK_EQ(Smi::FromInt(20),
102 *helper.Invoke(helper.NewObject("(function() { return this.x; })"), 201 *helper.Invoke(helper.NewObject("(function() { return this.x; })"),
103 helper.NewObject("({ x: 20 })"))); 202 helper.NewObject("({ x: 20 })")));
104 CHECK_EQ(Smi::FromInt(50), 203 CHECK_EQ(Smi::FromInt(50),
105 *helper.Invoke(helper.NewObject("(function(arg1) { return arg1; })"), 204 *helper.Invoke(helper.NewObject("(function(arg1) { return arg1; })"),
106 factory->undefined_value(), 205 factory->undefined_value(),
107 handle(Smi::FromInt(50), isolate))); 206 handle(Smi::FromInt(50), isolate)));
108 CHECK_EQ( 207 CHECK_EQ(
109 Smi::FromInt(20), 208 Smi::FromInt(20),
110 *helper.Invoke( 209 *helper.Invoke(
111 helper.NewObject("(function(a, b, c) { return a + b + c; })"), 210 helper.NewObject("(function(a, b, c) { return a + b + c; })"),
112 factory->undefined_value(), handle(Smi::FromInt(10), isolate), 211 factory->undefined_value(), handle(Smi::FromInt(10), isolate),
113 handle(Smi::FromInt(7), isolate), handle(Smi::FromInt(3), isolate))); 212 handle(Smi::FromInt(7), isolate), handle(Smi::FromInt(3), isolate)));
114 } 213 }
115 214
116 } // namespace interpreter 215 } // namespace interpreter
117 } // namespace internal 216 } // namespace internal
118 } // namespace v8 217 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter-intrinsics.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698