OLD | NEW |
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/execution.h" | 7 #include "src/execution.h" |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 2181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2192 }; | 2192 }; |
2193 | 2193 |
2194 for (size_t i = 0; i < arraysize(compound_expr); i++) { | 2194 for (size_t i = 0; i < arraysize(compound_expr); i++) { |
2195 InterpreterTester tester(handles.main_isolate(), compound_expr[i].first); | 2195 InterpreterTester tester(handles.main_isolate(), compound_expr[i].first); |
2196 auto callable = tester.GetCallable<>(); | 2196 auto callable = tester.GetCallable<>(); |
2197 | 2197 |
2198 Handle<i::Object> return_value = callable().ToHandleChecked(); | 2198 Handle<i::Object> return_value = callable().ToHandleChecked(); |
2199 CHECK(return_value->SameValue(*compound_expr[i].second)); | 2199 CHECK(return_value->SameValue(*compound_expr[i].second)); |
2200 } | 2200 } |
2201 } | 2201 } |
| 2202 |
| 2203 |
| 2204 TEST(InterpreterCreateArguments) { |
| 2205 HandleAndZoneScope handles; |
| 2206 i::Isolate* isolate = handles.main_isolate(); |
| 2207 i::Factory* factory = isolate->factory(); |
| 2208 |
| 2209 std::pair<const char*, int> create_args[9] = { |
| 2210 std::make_pair("function f() { return arguments[0]; }", 0), |
| 2211 std::make_pair("function f(a) { return arguments[0]; }", 0), |
| 2212 std::make_pair("function f() { return arguments[2]; }", 2), |
| 2213 std::make_pair("function f(a) { return arguments[2]; }", 2), |
| 2214 std::make_pair("function f(a, b, c, d) { return arguments[2]; }", 2), |
| 2215 std::make_pair("function f(a) {" |
| 2216 "'use strict'; return arguments[0]; }", |
| 2217 0), |
| 2218 std::make_pair("function f(a, b, c, d) {" |
| 2219 "'use strict'; return arguments[2]; }", |
| 2220 2), |
| 2221 // Check arguments are mapped in sloppy mode and unmapped in strict. |
| 2222 std::make_pair("function f(a, b, c, d) {" |
| 2223 " c = b; return arguments[2]; }", |
| 2224 1), |
| 2225 std::make_pair("function f(a, b, c, d) {" |
| 2226 " 'use strict'; c = b; return arguments[2]; }", |
| 2227 2), |
| 2228 }; |
| 2229 |
| 2230 // Test passing no arguments. |
| 2231 for (size_t i = 0; i < arraysize(create_args); i++) { |
| 2232 InterpreterTester tester(handles.main_isolate(), create_args[i].first); |
| 2233 auto callable = tester.GetCallable<>(); |
| 2234 Handle<Object> return_val = callable().ToHandleChecked(); |
| 2235 CHECK(return_val.is_identical_to(factory->undefined_value())); |
| 2236 } |
| 2237 |
| 2238 // Test passing one argument. |
| 2239 for (size_t i = 0; i < arraysize(create_args); i++) { |
| 2240 InterpreterTester tester(handles.main_isolate(), create_args[i].first); |
| 2241 auto callable = tester.GetCallable<Handle<Object>>(); |
| 2242 Handle<Object> return_val = |
| 2243 callable(handle(Smi::FromInt(40), isolate)).ToHandleChecked(); |
| 2244 if (create_args[i].second == 0) { |
| 2245 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(40)); |
| 2246 } else { |
| 2247 CHECK(return_val.is_identical_to(factory->undefined_value())); |
| 2248 } |
| 2249 } |
| 2250 |
| 2251 // Test passing three argument. |
| 2252 for (size_t i = 0; i < arraysize(create_args); i++) { |
| 2253 Handle<Object> args[3] = { |
| 2254 handle(Smi::FromInt(40), isolate), |
| 2255 handle(Smi::FromInt(60), isolate), |
| 2256 handle(Smi::FromInt(80), isolate), |
| 2257 }; |
| 2258 |
| 2259 InterpreterTester tester(handles.main_isolate(), create_args[i].first); |
| 2260 auto callable = |
| 2261 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); |
| 2262 Handle<Object> return_val = |
| 2263 callable(args[0], args[1], args[2]).ToHandleChecked(); |
| 2264 CHECK(return_val->SameValue(*args[create_args[i].second])); |
| 2265 } |
| 2266 } |
OLD | NEW |