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 3033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3044 InterpreterTester tester(handles.main_isolate(), samples[i].first); | 3044 InterpreterTester tester(handles.main_isolate(), samples[i].first); |
3045 auto callable = tester.GetCallable<Handle<Object>>(); | 3045 auto callable = tester.GetCallable<Handle<Object>>(); |
3046 Handle<Object> return_val = | 3046 Handle<Object> return_val = |
3047 callable(handle(Smi::FromInt(arg_value), handles.main_isolate())) | 3047 callable(handle(Smi::FromInt(arg_value), handles.main_isolate())) |
3048 .ToHandleChecked(); | 3048 .ToHandleChecked(); |
3049 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second); | 3049 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), samples[i].second); |
3050 } | 3050 } |
3051 } | 3051 } |
3052 | 3052 |
3053 | 3053 |
| 3054 TEST(InterpreterToName) { |
| 3055 HandleAndZoneScope handles; |
| 3056 i::Isolate* isolate = handles.main_isolate(); |
| 3057 i::Factory* factory = isolate->factory(); |
| 3058 |
| 3059 std::pair<const char*, Handle<Object>> to_name_tests[] = { |
| 3060 {"var a = 'val'; var obj = {[a] : 10}; return obj.val;", |
| 3061 factory->NewNumberFromInt(10)}, |
| 3062 {"var a = 20; var obj = {[a] : 10}; return obj['20'];", |
| 3063 factory->NewNumberFromInt(10)}, |
| 3064 {"var a = 20; var obj = {[a] : 10}; return obj[20];", |
| 3065 factory->NewNumberFromInt(10)}, |
| 3066 {"var a = {val:23}; var obj = {[a] : 10}; return obj[a];", |
| 3067 factory->NewNumberFromInt(10)}, |
| 3068 {"var a = {val:23}; var obj = {[a] : 10};\n" |
| 3069 "return obj['[object Object]'];", |
| 3070 factory->NewNumberFromInt(10)}, |
| 3071 {"var a = {toString : function() { return 'x'}};\n" |
| 3072 "var obj = {[a] : 10};\n" |
| 3073 "return obj.x;", |
| 3074 factory->NewNumberFromInt(10)}, |
| 3075 {"var a = {valueOf : function() { return 'x'}};\n" |
| 3076 "var obj = {[a] : 10};\n" |
| 3077 "return obj.x;", |
| 3078 factory->undefined_value()}, |
| 3079 {"var a = {[Symbol.toPrimitive] : function() { return 'x'}};\n" |
| 3080 "var obj = {[a] : 10};\n" |
| 3081 "return obj.x;", |
| 3082 factory->NewNumberFromInt(10)}, |
| 3083 }; |
| 3084 |
| 3085 for (size_t i = 0; i < arraysize(to_name_tests); i++) { |
| 3086 std::string source( |
| 3087 InterpreterTester::SourceForBody(to_name_tests[i].first)); |
| 3088 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 3089 auto callable = tester.GetCallable<>(); |
| 3090 |
| 3091 Handle<i::Object> return_value = callable().ToHandleChecked(); |
| 3092 CHECK(return_value->SameValue(*to_name_tests[i].second)); |
| 3093 } |
| 3094 } |
| 3095 |
3054 } // namespace interpreter | 3096 } // namespace interpreter |
3055 } // namespace internal | 3097 } // namespace internal |
3056 } // namespace v8 | 3098 } // namespace v8 |
OLD | NEW |