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/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 5839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5850 int closure = Register::function_closure().index(); | 5850 int closure = Register::function_closure().index(); |
5851 int context = Register::function_context().index(); | 5851 int context = Register::function_context().index(); |
5852 int new_target = Register::new_target().index(); | 5852 int new_target = Register::new_target().index(); |
5853 | 5853 |
5854 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 5854 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
5855 | 5855 |
5856 ExpectedSnippet<const char*> snippets[] = { | 5856 ExpectedSnippet<const char*> snippets[] = { |
5857 {"return eval('1;');", | 5857 {"return eval('1;');", |
5858 9 * kPointerSize, | 5858 9 * kPointerSize, |
5859 1, | 5859 1, |
5860 73, | 5860 67, |
5861 { | 5861 { |
5862 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 5862 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
5863 U8(1), // | 5863 U8(1), // |
5864 B(PushContext), R(0), // | 5864 B(PushContext), R(0), // |
5865 B(Ldar), THIS(1), // | 5865 B(Ldar), THIS(1), // |
5866 B(StaContextSlot), R(0), U8(first_context_slot), // | 5866 B(StaContextSlot), R(0), U8(first_context_slot), // |
5867 B(CreateMappedArguments), // | 5867 B(CreateMappedArguments), // |
5868 B(StaContextSlot), R(0), U8(first_context_slot + 1), // | 5868 B(StaContextSlot), R(0), U8(first_context_slot + 1), // |
5869 B(Ldar), R(new_target), // | 5869 B(Ldar), R(new_target), // |
5870 B(StaContextSlot), R(0), U8(first_context_slot + 2), // | 5870 B(StaContextSlot), R(0), U8(first_context_slot + 2), // |
5871 B(Mov), R(context), R(3), // | 5871 B(Mov), R(context), R(3), // |
5872 B(LdaConstant), U8(0), // | 5872 B(LdaConstant), U8(0), // |
5873 B(Star), R(4), // | 5873 B(Star), R(4), // |
5874 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // | 5874 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
5875 R(3), U8(2), R(3), // | 5875 R(3), U8(2), R(1), // |
5876 B(Mov), R(3), R(1), // | |
5877 B(Mov), R(4), R(2), // | |
5878 B(LdaConstant), U8(1), // | 5876 B(LdaConstant), U8(1), // |
5879 B(Star), R(3), // | 5877 B(Star), R(3), // |
5880 B(Mov), R(1), R(4), // | 5878 B(Mov), R(1), R(4), // |
5881 B(Mov), R(3), R(5), // | 5879 B(Mov), R(3), R(5), // |
5882 B(Mov), R(closure), R(6), // | 5880 B(Mov), R(closure), R(6), // |
5883 B(LdaZero), // | 5881 B(LdaZero), // |
5884 B(Star), R(7), // | 5882 B(Star), R(7), // |
5885 B(LdaSmi8), U8(10), // | 5883 B(LdaSmi8), U8(10), // |
5886 B(Star), R(8), // | 5884 B(Star), R(8), // |
5887 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // | 5885 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // |
(...skipping 20 matching lines...) Expand all Loading... |
5908 | 5906 |
5909 int closure = Register::function_closure().index(); | 5907 int closure = Register::function_closure().index(); |
5910 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 5908 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
5911 int context = Register::function_context().index(); | 5909 int context = Register::function_context().index(); |
5912 int new_target = Register::new_target().index(); | 5910 int new_target = Register::new_target().index(); |
5913 | 5911 |
5914 ExpectedSnippet<const char*> snippets[] = { | 5912 ExpectedSnippet<const char*> snippets[] = { |
5915 {"eval('var x = 10;'); return x;", | 5913 {"eval('var x = 10;'); return x;", |
5916 9 * kPointerSize, | 5914 9 * kPointerSize, |
5917 1, | 5915 1, |
5918 75, | 5916 69, |
5919 { | 5917 { |
5920 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 5918 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
5921 U8(1), // | 5919 U8(1), // |
5922 B(PushContext), R(0), // | 5920 B(PushContext), R(0), // |
5923 B(Ldar), THIS(1), // | 5921 B(Ldar), THIS(1), // |
5924 B(StaContextSlot), R(0), U8(first_context_slot), // | 5922 B(StaContextSlot), R(0), U8(first_context_slot), // |
5925 B(CreateMappedArguments), // | 5923 B(CreateMappedArguments), // |
5926 B(StaContextSlot), R(0), U8(first_context_slot + 1), // | 5924 B(StaContextSlot), R(0), U8(first_context_slot + 1), // |
5927 B(Ldar), R(new_target), // | 5925 B(Ldar), R(new_target), // |
5928 B(StaContextSlot), R(0), U8(first_context_slot + 2), // | 5926 B(StaContextSlot), R(0), U8(first_context_slot + 2), // |
5929 B(Mov), R(context), R(3), // | 5927 B(Mov), R(context), R(3), // |
5930 B(LdaConstant), U8(0), // | 5928 B(LdaConstant), U8(0), // |
5931 B(Star), R(4), // | 5929 B(Star), R(4), // |
5932 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // | 5930 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
5933 R(3), U8(2), R(3), // | 5931 R(3), U8(2), R(1), // |
5934 B(Mov), R(3), R(1), // | |
5935 B(Mov), R(4), R(2), // | |
5936 B(LdaConstant), U8(1), // | 5932 B(LdaConstant), U8(1), // |
5937 B(Star), R(3), // | 5933 B(Star), R(3), // |
5938 B(Mov), R(1), R(4), // | 5934 B(Mov), R(1), R(4), // |
5939 B(Mov), R(3), R(5), // | 5935 B(Mov), R(3), R(5), // |
5940 B(Mov), R(closure), R(6), // | 5936 B(Mov), R(closure), R(6), // |
5941 B(LdaZero), // | 5937 B(LdaZero), // |
5942 B(Star), R(7), // | 5938 B(Star), R(7), // |
5943 B(LdaSmi8), U8(10), // | 5939 B(LdaSmi8), U8(10), // |
5944 B(Star), R(8), // | 5940 B(Star), R(8), // |
5945 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // | 5941 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // |
5946 U8(5), // | 5942 U8(5), // |
5947 B(Star), R(1), // | 5943 B(Star), R(1), // |
5948 B(Call), R(1), R(2), U8(1), U8(0), // | 5944 B(Call), R(1), R(2), U8(1), U8(0), // |
5949 B(LdaLookupSlot), U8(2), // | 5945 B(LdaLookupSlot), U8(2), // |
5950 B(Return), // | 5946 B(Return), // |
5951 }, | 5947 }, |
5952 3, | 5948 3, |
5953 {"eval", "var x = 10;", "x"}}, | 5949 {"eval", "var x = 10;", "x"}}, |
5954 {"eval('var x = 10;'); return typeof x;", | 5950 {"eval('var x = 10;'); return typeof x;", |
5955 9 * kPointerSize, | 5951 9 * kPointerSize, |
5956 1, | 5952 1, |
5957 76, | 5953 70, |
5958 { | 5954 { |
5959 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 5955 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
5960 U8(1), // | 5956 U8(1), // |
5961 B(PushContext), R(0), // | 5957 B(PushContext), R(0), // |
5962 B(Ldar), THIS(1), // | 5958 B(Ldar), THIS(1), // |
5963 B(StaContextSlot), R(0), U8(first_context_slot), // | 5959 B(StaContextSlot), R(0), U8(first_context_slot), // |
5964 B(CreateMappedArguments), // | 5960 B(CreateMappedArguments), // |
5965 B(StaContextSlot), R(0), U8(first_context_slot + 1), // | 5961 B(StaContextSlot), R(0), U8(first_context_slot + 1), // |
5966 B(Ldar), R(new_target), // | 5962 B(Ldar), R(new_target), // |
5967 B(StaContextSlot), R(0), U8(first_context_slot + 2), // | 5963 B(StaContextSlot), R(0), U8(first_context_slot + 2), // |
5968 B(Mov), R(context), R(3), // | 5964 B(Mov), R(context), R(3), // |
5969 B(LdaConstant), U8(0), // | 5965 B(LdaConstant), U8(0), // |
5970 B(Star), R(4), // | 5966 B(Star), R(4), // |
5971 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // | 5967 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
5972 R(3), U8(2), R(3), // | 5968 R(3), U8(2), R(1), // |
5973 B(Mov), R(3), R(1), // | |
5974 B(Mov), R(4), R(2), // | |
5975 B(LdaConstant), U8(1), // | 5969 B(LdaConstant), U8(1), // |
5976 B(Star), R(3), // | 5970 B(Star), R(3), // |
5977 B(Mov), R(1), R(4), // | 5971 B(Mov), R(1), R(4), // |
5978 B(Mov), R(3), R(5), // | 5972 B(Mov), R(3), R(5), // |
5979 B(Mov), R(closure), R(6), // | 5973 B(Mov), R(closure), R(6), // |
5980 B(LdaZero), // | 5974 B(LdaZero), // |
5981 B(Star), R(7), // | 5975 B(Star), R(7), // |
5982 B(LdaSmi8), U8(10), // | 5976 B(LdaSmi8), U8(10), // |
5983 B(Star), R(8), // | 5977 B(Star), R(8), // |
5984 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // | 5978 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // |
5985 U8(5), // | 5979 U8(5), // |
5986 B(Star), R(1), // | 5980 B(Star), R(1), // |
5987 B(Call), R(1), R(2), U8(1), U8(0), // | 5981 B(Call), R(1), R(2), U8(1), U8(0), // |
5988 B(LdaLookupSlotInsideTypeof), U8(2), // | 5982 B(LdaLookupSlotInsideTypeof), U8(2), // |
5989 B(TypeOf), // | 5983 B(TypeOf), // |
5990 B(Return), // | 5984 B(Return), // |
5991 }, | 5985 }, |
5992 3, | 5986 3, |
5993 {"eval", "var x = 10;", "x"}}, | 5987 {"eval", "var x = 10;", "x"}}, |
5994 {"x = 20; return eval('');", | 5988 {"x = 20; return eval('');", |
5995 9 * kPointerSize, | 5989 9 * kPointerSize, |
5996 1, | 5990 1, |
5997 77, | 5991 71, |
5998 { | 5992 { |
5999 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | 5993 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
6000 U8(1), // | 5994 U8(1), // |
6001 B(PushContext), R(0), // | 5995 B(PushContext), R(0), // |
6002 B(Ldar), THIS(1), // | 5996 B(Ldar), THIS(1), // |
6003 B(StaContextSlot), R(0), U8(first_context_slot), // | 5997 B(StaContextSlot), R(0), U8(first_context_slot), // |
6004 B(CreateMappedArguments), // | 5998 B(CreateMappedArguments), // |
6005 B(StaContextSlot), R(0), U8(first_context_slot + 1), // | 5999 B(StaContextSlot), R(0), U8(first_context_slot + 1), // |
6006 B(Ldar), R(new_target), // | 6000 B(Ldar), R(new_target), // |
6007 B(StaContextSlot), R(0), U8(first_context_slot + 2), // | 6001 B(StaContextSlot), R(0), U8(first_context_slot + 2), // |
6008 B(LdaSmi8), U8(20), // | 6002 B(LdaSmi8), U8(20), // |
6009 B(StaLookupSlotSloppy), U8(0), // | 6003 B(StaLookupSlotSloppy), U8(0), // |
6010 B(Mov), R(context), R(3), // | 6004 B(Mov), R(context), R(3), // |
6011 B(LdaConstant), U8(1), // | 6005 B(LdaConstant), U8(1), // |
6012 B(Star), R(4), // | 6006 B(Star), R(4), // |
6013 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // | 6007 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
6014 R(3), U8(2), R(3), // | 6008 R(3), U8(2), R(1), // |
6015 B(Mov), R(3), R(1), // | |
6016 B(Mov), R(4), R(2), // | |
6017 B(LdaConstant), U8(2), // | 6009 B(LdaConstant), U8(2), // |
6018 B(Star), R(3), // | 6010 B(Star), R(3), // |
6019 B(Mov), R(1), R(4), // | 6011 B(Mov), R(1), R(4), // |
6020 B(Mov), R(3), R(5), // | 6012 B(Mov), R(3), R(5), // |
6021 B(Mov), R(closure), R(6), // | 6013 B(Mov), R(closure), R(6), // |
6022 B(LdaZero), // | 6014 B(LdaZero), // |
6023 B(Star), R(7), // | 6015 B(Star), R(7), // |
6024 B(LdaSmi8), U8(10), // | 6016 B(LdaSmi8), U8(10), // |
6025 B(Star), R(8), // | 6017 B(Star), R(8), // |
6026 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // | 6018 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // |
6027 U8(5), // | 6019 U8(5), // |
6028 B(Star), R(1), // | 6020 B(Star), R(1), // |
6029 B(Call), R(1), R(2), U8(1), U8(0), // | 6021 B(Call), R(1), R(2), U8(1), U8(0), // |
6030 B(Return), // | 6022 B(Return), // |
6031 }, | 6023 }, |
6032 3, | 6024 3, |
6033 {"x", "eval", ""}}, | 6025 {"x", "eval", ""}}, |
6034 }; | 6026 }; |
6035 | 6027 |
6036 for (size_t i = 0; i < arraysize(snippets); i++) { | 6028 for (size_t i = 0; i < arraysize(snippets); i++) { |
6037 Handle<BytecodeArray> bytecode_array = | 6029 Handle<BytecodeArray> bytecode_array = |
6038 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 6030 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
6039 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6031 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
6040 } | 6032 } |
6041 } | 6033 } |
6042 | 6034 |
6043 | 6035 |
| 6036 TEST(CallLookupSlot) { |
| 6037 InitializedHandleScope handle_scope; |
| 6038 BytecodeGeneratorHelper helper; |
| 6039 Zone zone; |
| 6040 |
| 6041 FeedbackVectorSpec feedback_spec(&zone); |
| 6042 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); |
| 6043 FeedbackVectorSlot slot2 = feedback_spec.AddCallICSlot(); |
| 6044 USE(slot1); |
| 6045 |
| 6046 Handle<i::TypeFeedbackVector> vector = |
| 6047 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 6048 |
| 6049 int closure = Register::function_closure().index(); |
| 6050 int context = Register::function_context().index(); |
| 6051 int new_target = Register::new_target().index(); |
| 6052 |
| 6053 ExpectedSnippet<InstanceType> snippets[] = { |
| 6054 {"g = function(){}; eval(''); return g();", |
| 6055 9 * kPointerSize, |
| 6056 1, |
| 6057 90, |
| 6058 { |
| 6059 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 6060 U8(1), // |
| 6061 B(PushContext), R(0), // |
| 6062 B(Ldar), THIS(1), // |
| 6063 B(StaContextSlot), R(0), U8(4), // |
| 6064 B(CreateMappedArguments), // |
| 6065 B(StaContextSlot), R(0), U8(5), // |
| 6066 B(Ldar), R(new_target), // |
| 6067 B(StaContextSlot), R(0), U8(6), // |
| 6068 B(CreateClosure), U8(0), U8(0), // |
| 6069 B(StaLookupSlotSloppy), U8(1), // |
| 6070 B(Mov), R(context), R(3), // |
| 6071 B(LdaConstant), U8(2), // |
| 6072 B(Star), R(4), // |
| 6073 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
| 6074 R(3), U8(2), R(1), // |
| 6075 B(LdaConstant), U8(3), // |
| 6076 B(Star), R(3), // |
| 6077 B(Mov), R(1), R(4), // |
| 6078 B(Mov), R(3), R(5), // |
| 6079 B(Mov), R(closure), R(6), // |
| 6080 B(LdaZero), // |
| 6081 B(Star), R(7), // |
| 6082 B(LdaSmi8), U8(10), // |
| 6083 B(Star), R(8), // |
| 6084 B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(4), // |
| 6085 U8(5), // |
| 6086 B(Star), R(1), // |
| 6087 B(Call), R(1), R(2), U8(1), U8(0), // |
| 6088 B(Mov), R(context), R(3), // |
| 6089 B(LdaConstant), U8(1), // |
| 6090 B(Star), R(4), // |
| 6091 B(CallRuntimeForPair), U16(Runtime::kLoadLookupSlot), // |
| 6092 R(3), U8(2), R(1), // |
| 6093 B(Call), R(1), R(2), U8(0), U8(vector->GetIndex(slot2)), // |
| 6094 B(Return), // |
| 6095 }, |
| 6096 4, |
| 6097 {InstanceType::SHARED_FUNCTION_INFO_TYPE, |
| 6098 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 6099 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 6100 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 6101 }; |
| 6102 |
| 6103 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 6104 Handle<BytecodeArray> bytecode_array = |
| 6105 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 6106 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6107 } |
| 6108 } |
| 6109 |
| 6110 |
6044 TEST(LookupSlotInEval) { | 6111 TEST(LookupSlotInEval) { |
6045 InitializedHandleScope handle_scope; | 6112 InitializedHandleScope handle_scope; |
6046 BytecodeGeneratorHelper helper; | 6113 BytecodeGeneratorHelper helper; |
6047 | 6114 |
6048 const char* function_prologue = "var f;" | 6115 const char* function_prologue = "var f;" |
6049 "var x = 1;" | 6116 "var x = 1;" |
6050 "function f1() {" | 6117 "function f1() {" |
6051 " eval(\"function t() {"; | 6118 " eval(\"function t() {"; |
6052 const char* function_epilogue = " }; f = t; f();\");" | 6119 const char* function_epilogue = " }; f = t; f();\");" |
6053 "}" | 6120 "}" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6266 std::string(function_epilogue); | 6333 std::string(function_epilogue); |
6267 Handle<BytecodeArray> bytecode_array = | 6334 Handle<BytecodeArray> bytecode_array = |
6268 helper.MakeBytecode(script.c_str(), "t", "f"); | 6335 helper.MakeBytecode(script.c_str(), "t", "f"); |
6269 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6336 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
6270 } | 6337 } |
6271 } | 6338 } |
6272 | 6339 |
6273 } // namespace interpreter | 6340 } // namespace interpreter |
6274 } // namespace internal | 6341 } // namespace internal |
6275 } // namespace v8 | 6342 } // namespace v8 |
OLD | NEW |