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 5820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5831 std::string(function_epilogue); | 5831 std::string(function_epilogue); |
5832 // TODO(mythria): use * as filter when function declarations are supported | 5832 // TODO(mythria): use * as filter when function declarations are supported |
5833 // inside eval. | 5833 // inside eval. |
5834 Handle<BytecodeArray> bytecode_array = | 5834 Handle<BytecodeArray> bytecode_array = |
5835 helper.MakeBytecode(script.c_str(), "t", "f"); | 5835 helper.MakeBytecode(script.c_str(), "t", "f"); |
5836 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5836 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
5837 } | 5837 } |
5838 } | 5838 } |
5839 | 5839 |
5840 | 5840 |
| 5841 TEST(LookupSlotWideInEval) { |
| 5842 InitializedHandleScope handle_scope; |
| 5843 BytecodeGeneratorHelper helper; |
| 5844 |
| 5845 const char* function_prologue = |
| 5846 "var f;" |
| 5847 "var x = 1;" |
| 5848 "function f1() {" |
| 5849 " eval(\"function t() {"; |
| 5850 const char* function_epilogue = |
| 5851 " }; f = t; f();\");" |
| 5852 "}" |
| 5853 "f1();"; |
| 5854 |
| 5855 int const_count[] = {0, 0, 0, 0}; |
| 5856 ExpectedSnippet<InstanceType, 257> snippets[] = { |
| 5857 {REPEAT_256(SPACE, "var y = 2.3;") |
| 5858 "return x;", |
| 5859 1 * kPointerSize, |
| 5860 1, |
| 5861 1028, |
| 5862 { |
| 5863 REPEAT_256(SPACE, // |
| 5864 B(LdaConstant), U8(const_count[0]++), // |
| 5865 B(Star), R(0), ) // |
| 5866 B(LdaLookupSlotWide), U16(256), // |
| 5867 B(Return) // |
| 5868 }, |
| 5869 257, |
| 5870 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 5871 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5872 {REPEAT_256(SPACE, "var y = 2.3;") |
| 5873 "return typeof x;", |
| 5874 1 * kPointerSize, |
| 5875 1, |
| 5876 1029, |
| 5877 { |
| 5878 REPEAT_256(SPACE, // |
| 5879 B(LdaConstant), U8(const_count[1]++), // |
| 5880 B(Star), R(0), ) // |
| 5881 B(LdaLookupSlotInsideTypeofWide), U16(256), // |
| 5882 B(TypeOf), // |
| 5883 B(Return) // |
| 5884 }, |
| 5885 257, |
| 5886 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 5887 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5888 {REPEAT_256(SPACE, "var y = 2.3;") |
| 5889 "x = 10;", |
| 5890 1 * kPointerSize, |
| 5891 1, |
| 5892 1031, |
| 5893 { |
| 5894 REPEAT_256(SPACE, // |
| 5895 B(LdaConstant), U8(const_count[2]++), // |
| 5896 B(Star), R(0), ) // |
| 5897 B(LdaSmi8), U8(10), // |
| 5898 B(StaLookupSlotSloppyWide), U16(256), // |
| 5899 B(LdaUndefined), // |
| 5900 B(Return) // |
| 5901 }, |
| 5902 257, |
| 5903 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 5904 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5905 {"'use strict';" |
| 5906 REPEAT_256(SPACE, "var y = 2.3;") |
| 5907 "x = 10;", |
| 5908 1 * kPointerSize, |
| 5909 1, |
| 5910 1031, |
| 5911 { |
| 5912 REPEAT_256(SPACE, |
| 5913 B(LdaConstant), U8(const_count[3]++), // |
| 5914 B(Star), R(0), ) // |
| 5915 B(LdaSmi8), U8(10), // |
| 5916 B(StaLookupSlotStrictWide), U16(256), // |
| 5917 B(LdaUndefined), // |
| 5918 B(Return) // |
| 5919 }, |
| 5920 257, |
| 5921 {REPEAT_256(COMMA, InstanceType::HEAP_NUMBER_TYPE), |
| 5922 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 5923 }; |
| 5924 |
| 5925 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 5926 std::string script = std::string(function_prologue) + |
| 5927 std::string(snippets[i].code_snippet) + |
| 5928 std::string(function_epilogue); |
| 5929 // TODO(mythria): use * as filter when function declarations are supported |
| 5930 // inside eval. |
| 5931 Handle<BytecodeArray> bytecode_array = |
| 5932 helper.MakeBytecode(script.c_str(), "t", "f"); |
| 5933 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 5934 } |
| 5935 } |
| 5936 |
| 5937 |
5841 TEST(DeleteLookupSlot) { | 5938 TEST(DeleteLookupSlot) { |
5842 InitializedHandleScope handle_scope; | 5939 InitializedHandleScope handle_scope; |
5843 BytecodeGeneratorHelper helper; | 5940 BytecodeGeneratorHelper helper; |
5844 | 5941 |
5845 const char* function_prologue = "var f;" | 5942 const char* function_prologue = "var f;" |
5846 "var x = 1;" | 5943 "var x = 1;" |
5847 "z = 10;" | 5944 "z = 10;" |
5848 "function f1() {" | 5945 "function f1() {" |
5849 " var y;" | 5946 " var y;" |
5850 " eval(\"function t() {"; | 5947 " eval(\"function t() {"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5893 std::string(function_epilogue); | 5990 std::string(function_epilogue); |
5894 Handle<BytecodeArray> bytecode_array = | 5991 Handle<BytecodeArray> bytecode_array = |
5895 helper.MakeBytecode(script.c_str(), "t", "f"); | 5992 helper.MakeBytecode(script.c_str(), "t", "f"); |
5896 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5993 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
5897 } | 5994 } |
5898 } | 5995 } |
5899 | 5996 |
5900 } // namespace interpreter | 5997 } // namespace interpreter |
5901 } // namespace internal | 5998 } // namespace internal |
5902 } // namespace v8 | 5999 } // namespace v8 |
OLD | NEW |