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 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 "(function() { try { f(); } catch(e) { return e; }})()"; | 2055 "(function() { try { f(); } catch(e) { return e; }})()"; |
2056 | 2056 |
2057 for (size_t i = 0; i < arraysize(throws); i++) { | 2057 for (size_t i = 0; i < arraysize(throws); i++) { |
2058 std::string source(InterpreterTester::SourceForBody(throws[i].first)); | 2058 std::string source(InterpreterTester::SourceForBody(throws[i].first)); |
2059 InterpreterTester tester(handles.main_isolate(), source.c_str()); | 2059 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
2060 tester.GetCallable<>(); | 2060 tester.GetCallable<>(); |
2061 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); | 2061 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); |
2062 CHECK(thrown_obj->SameValue(*throws[i].second)); | 2062 CHECK(thrown_obj->SameValue(*throws[i].second)); |
2063 } | 2063 } |
2064 } | 2064 } |
| 2065 |
| 2066 |
| 2067 TEST(InterpreterCreateArguments) { |
| 2068 HandleAndZoneScope handles; |
| 2069 i::Isolate* isolate = handles.main_isolate(); |
| 2070 i::Factory* factory = isolate->factory(); |
| 2071 |
| 2072 std::pair<const char*, int> create_args[9] = { |
| 2073 std::make_pair("function f() { return arguments[0]; }", 0), |
| 2074 std::make_pair("function f(a) { return arguments[0]; }", 0), |
| 2075 std::make_pair("function f() { return arguments[2]; }", 2), |
| 2076 std::make_pair("function f(a) { return arguments[2]; }", 2), |
| 2077 std::make_pair("function f(a, b, c, d) { return arguments[2]; }", 2), |
| 2078 std::make_pair("function f(a) {" |
| 2079 "'use strict'; return arguments[0]; }", |
| 2080 0), |
| 2081 std::make_pair("function f(a, b, c, d) {" |
| 2082 "'use strict'; return arguments[2]; }", |
| 2083 2), |
| 2084 // Check arguments are aliased in sloppy mode and non-aliased in strict. |
| 2085 std::make_pair("function f(a, b, c, d) {" |
| 2086 " c = b; return arguments[2]; }", |
| 2087 1), |
| 2088 std::make_pair("function f(a, b, c, d) {" |
| 2089 " 'use strict'; c = b; return arguments[2]; }", |
| 2090 2), |
| 2091 }; |
| 2092 |
| 2093 // Test passing no arguments. |
| 2094 for (size_t i = 0; i < arraysize(create_args); i++) { |
| 2095 InterpreterTester tester(handles.main_isolate(), create_args[i].first); |
| 2096 auto callable = tester.GetCallable<>(); |
| 2097 Handle<Object> return_val = callable().ToHandleChecked(); |
| 2098 CHECK(return_val.is_identical_to(factory->undefined_value())); |
| 2099 } |
| 2100 |
| 2101 // Test passing one argument. |
| 2102 for (size_t i = 0; i < arraysize(create_args); i++) { |
| 2103 InterpreterTester tester(handles.main_isolate(), create_args[i].first); |
| 2104 auto callable = tester.GetCallable<Handle<Object>>(); |
| 2105 Handle<Object> return_val = |
| 2106 callable(handle(Smi::FromInt(40), isolate)).ToHandleChecked(); |
| 2107 if (create_args[i].second == 0) { |
| 2108 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(40)); |
| 2109 } else { |
| 2110 CHECK(return_val.is_identical_to(factory->undefined_value())); |
| 2111 } |
| 2112 } |
| 2113 |
| 2114 // Test passing three argument. |
| 2115 for (size_t i = 0; i < arraysize(create_args); i++) { |
| 2116 Handle<Object> args[3] = { |
| 2117 handle(Smi::FromInt(40), isolate), |
| 2118 handle(Smi::FromInt(60), isolate), |
| 2119 handle(Smi::FromInt(80), isolate), |
| 2120 }; |
| 2121 |
| 2122 InterpreterTester tester(handles.main_isolate(), create_args[i].first); |
| 2123 auto callable = |
| 2124 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); |
| 2125 Handle<Object> return_val = |
| 2126 callable(args[0], args[1], args[2]).ToHandleChecked(); |
| 2127 CHECK(return_val->SameValue(*args[create_args[i].second])); |
| 2128 } |
| 2129 } |
OLD | NEW |