OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 | 28 |
29 #include "src/v8.h" | 29 #include "src/v8.h" |
30 | 30 |
31 #include "src/api.h" | 31 #include "src/api.h" |
32 #include "src/debug.h" | 32 #include "src/debug.h" |
33 #include "src/runtime/runtime.h" | 33 #include "src/string-search.h" |
34 #include "test/cctest/cctest.h" | 34 #include "test/cctest/cctest.h" |
35 | 35 |
36 | 36 |
37 using ::v8::internal::CStrVector; | 37 using ::v8::internal::CStrVector; |
38 using ::v8::internal::Factory; | 38 using ::v8::internal::Factory; |
39 using ::v8::internal::Handle; | 39 using ::v8::internal::Handle; |
40 using ::v8::internal::Heap; | 40 using ::v8::internal::Heap; |
41 using ::v8::internal::Isolate; | 41 using ::v8::internal::Isolate; |
42 using ::v8::internal::JSFunction; | 42 using ::v8::internal::JSFunction; |
43 using ::v8::internal::Object; | 43 using ::v8::internal::Object; |
44 using ::v8::internal::Runtime; | 44 using ::v8::internal::Runtime; |
45 using ::v8::internal::Script; | 45 using ::v8::internal::Script; |
46 using ::v8::internal::SmartArrayPointer; | 46 using ::v8::internal::SmartArrayPointer; |
47 using ::v8::internal::SharedFunctionInfo; | 47 using ::v8::internal::SharedFunctionInfo; |
48 using ::v8::internal::String; | 48 using ::v8::internal::String; |
| 49 using ::v8::internal::Vector; |
49 | 50 |
50 | 51 |
51 static void CheckFunctionName(v8::Handle<v8::Script> script, | 52 static void CheckFunctionName(v8::Handle<v8::Script> script, |
52 const char* func_pos_src, | 53 const char* func_pos_src, |
53 const char* ref_inferred_name) { | 54 const char* ref_inferred_name) { |
54 Isolate* isolate = CcTest::i_isolate(); | 55 Isolate* isolate = CcTest::i_isolate(); |
55 Factory* factory = isolate->factory(); | |
56 | 56 |
57 // Get script source. | 57 // Get script source. |
58 Handle<Object> obj = v8::Utils::OpenHandle(*script); | 58 Handle<Object> obj = v8::Utils::OpenHandle(*script); |
59 Handle<SharedFunctionInfo> shared_function; | 59 Handle<SharedFunctionInfo> shared_function; |
60 if (obj->IsSharedFunctionInfo()) { | 60 if (obj->IsSharedFunctionInfo()) { |
61 shared_function = | 61 shared_function = |
62 Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(*obj)); | 62 Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(*obj)); |
63 } else { | 63 } else { |
64 shared_function = | 64 shared_function = |
65 Handle<SharedFunctionInfo>(JSFunction::cast(*obj)->shared()); | 65 Handle<SharedFunctionInfo>(JSFunction::cast(*obj)->shared()); |
66 } | 66 } |
67 Handle<Script> i_script(Script::cast(shared_function->script())); | 67 Handle<Script> i_script(Script::cast(shared_function->script())); |
68 CHECK(i_script->source()->IsString()); | 68 CHECK(i_script->source()->IsString()); |
69 Handle<String> script_src(String::cast(i_script->source())); | 69 Handle<String> script_src(String::cast(i_script->source())); |
70 | 70 |
71 // Find the position of a given func source substring in the source. | 71 // Find the position of a given func source substring in the source. |
72 Handle<String> func_pos_str = | 72 int func_pos; |
73 factory->NewStringFromAsciiChecked(func_pos_src); | 73 { |
74 int func_pos = Runtime::StringMatch(isolate, | 74 i::DisallowHeapAllocation no_gc; |
75 script_src, | 75 Vector<const uint8_t> func_pos_str = i::OneByteVector(func_pos_src); |
76 func_pos_str, | 76 String::FlatContent script_content = script_src->GetFlatContent(); |
77 0); | 77 func_pos = SearchString(isolate, script_content.ToOneByteVector(), |
| 78 func_pos_str, 0); |
| 79 } |
78 CHECK_NE(0, func_pos); | 80 CHECK_NE(0, func_pos); |
79 | 81 |
80 // Obtain SharedFunctionInfo for the function. | 82 // Obtain SharedFunctionInfo for the function. |
81 isolate->debug()->PrepareForBreakPoints(); | 83 isolate->debug()->PrepareForBreakPoints(); |
82 Object* shared_func_info_ptr = | 84 Object* shared_func_info_ptr = |
83 isolate->debug()->FindSharedFunctionInfoInScript(i_script, func_pos); | 85 isolate->debug()->FindSharedFunctionInfoInScript(i_script, func_pos); |
84 CHECK(shared_func_info_ptr != CcTest::heap()->undefined_value()); | 86 CHECK(shared_func_info_ptr != CcTest::heap()->undefined_value()); |
85 Handle<SharedFunctionInfo> shared_func_info( | 87 Handle<SharedFunctionInfo> shared_func_info( |
86 SharedFunctionInfo::cast(shared_func_info_ptr)); | 88 SharedFunctionInfo::cast(shared_func_info_ptr)); |
87 | 89 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 " };\n" | 499 " };\n" |
498 " var foo = 10;\n" | 500 " var foo = 10;\n" |
499 " function f() {\n" | 501 " function f() {\n" |
500 " return wrapCode();\n" | 502 " return wrapCode();\n" |
501 " }\n" | 503 " }\n" |
502 " this.ref = f;\n" | 504 " this.ref = f;\n" |
503 "})()"); | 505 "})()"); |
504 script->Run(); | 506 script->Run(); |
505 CheckFunctionName(script, "return 2012", ""); | 507 CheckFunctionName(script, "return 2012", ""); |
506 } | 508 } |
OLD | NEW |