Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 14 matching lines...) Expand all Loading... | |
| 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 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "api.h" | 30 #include "api.h" |
| 31 #include "runtime.h" | 31 #include "runtime.h" |
| 32 #include "cctest.h" | 32 #include "cctest.h" |
| 33 | 33 |
| 34 | 34 |
| 35 using ::v8::internal::CStrVector; | |
|
Søren Thygesen Gjesse
2009/05/25 06:38:31
I must admit that I would prefer to not use "using
Mikhail Naganov
2009/05/25 08:38:51
Honestly, me too, because when using "using" it's
| |
| 36 using ::v8::internal::Factory; | |
| 35 using ::v8::internal::Handle; | 37 using ::v8::internal::Handle; |
| 38 using ::v8::internal::Heap; | |
| 36 using ::v8::internal::JSFunction; | 39 using ::v8::internal::JSFunction; |
| 37 using ::v8::internal::Object; | 40 using ::v8::internal::Object; |
| 41 using ::v8::internal::Runtime; | |
| 38 using ::v8::internal::Script; | 42 using ::v8::internal::Script; |
| 43 using ::v8::internal::SmartPointer; | |
| 39 using ::v8::internal::SharedFunctionInfo; | 44 using ::v8::internal::SharedFunctionInfo; |
| 40 using ::v8::internal::String; | 45 using ::v8::internal::String; |
| 41 | 46 |
| 42 namespace i = ::v8::internal; | |
| 43 | |
| 44 | 47 |
| 45 static v8::Persistent<v8::Context> env; | 48 static v8::Persistent<v8::Context> env; |
| 46 | 49 |
| 47 | 50 |
| 48 static void InitializeVM() { | 51 static void InitializeVM() { |
| 49 if (env.IsEmpty()) { | 52 if (env.IsEmpty()) { |
| 50 v8::HandleScope scope; | 53 v8::HandleScope scope; |
| 51 env = v8::Context::New(); | 54 env = v8::Context::New(); |
| 52 } | 55 } |
| 53 v8::HandleScope scope; | 56 v8::HandleScope scope; |
| 54 env->Enter(); | 57 env->Enter(); |
| 55 } | 58 } |
| 56 | 59 |
| 57 | 60 |
| 58 static void CheckFunctionName(v8::Handle<v8::Script> script, | 61 static void CheckFunctionName(v8::Handle<v8::Script> script, |
| 59 const char* func_pos_src, | 62 const char* func_pos_src, |
| 60 const char* ref_inferred_name) { | 63 const char* ref_inferred_name) { |
| 61 // Get script source. | 64 // Get script source. |
| 62 Handle<JSFunction> fun = v8::Utils::OpenHandle(*script); | 65 Handle<JSFunction> fun = v8::Utils::OpenHandle(*script); |
| 63 Handle<Script> i_script(Script::cast(fun->shared()->script())); | 66 Handle<Script> i_script(Script::cast(fun->shared()->script())); |
| 64 CHECK(i_script->source()->IsString()); | 67 CHECK(i_script->source()->IsString()); |
| 65 Handle<String> script_src(String::cast(i_script->source())); | 68 Handle<String> script_src(String::cast(i_script->source())); |
| 66 | 69 |
| 67 // Find the position of a given func source substring in the source. | 70 // Find the position of a given func source substring in the source. |
| 68 Handle<String> func_pos_str = | 71 Handle<String> func_pos_str = |
| 69 i::Factory::NewStringFromAscii(i::CStrVector(func_pos_src)); | 72 Factory::NewStringFromAscii(CStrVector(func_pos_src)); |
| 70 int func_pos = i::Runtime::StringMatch(script_src, func_pos_str, 0); | 73 int func_pos = Runtime::StringMatch(script_src, func_pos_str, 0); |
| 71 CHECK_NE(0, func_pos); | 74 CHECK_NE(0, func_pos); |
| 72 | 75 |
| 73 // Obtain SharedFunctionInfo for the function. | 76 // Obtain SharedFunctionInfo for the function. |
| 74 Object* shared_func_info_ptr = | 77 Object* shared_func_info_ptr = |
| 75 i::Runtime::FindSharedFunctionInfoInScript(i_script, func_pos); | 78 Runtime::FindSharedFunctionInfoInScript(i_script, func_pos); |
| 76 CHECK(shared_func_info_ptr != i::Heap::undefined_value()); | 79 CHECK(shared_func_info_ptr != Heap::undefined_value()); |
| 77 Handle<SharedFunctionInfo> shared_func_info( | 80 Handle<SharedFunctionInfo> shared_func_info( |
| 78 SharedFunctionInfo::cast(shared_func_info_ptr)); | 81 SharedFunctionInfo::cast(shared_func_info_ptr)); |
| 79 | 82 |
| 80 // Verify inferred function name. | 83 // Verify inferred function name. |
| 81 i::SmartPointer<char> inferred_name = | 84 SmartPointer<char> inferred_name = |
| 82 shared_func_info->inferred_name()->ToCString(); | 85 shared_func_info->inferred_name()->ToCString(); |
| 83 CHECK_EQ(ref_inferred_name, *inferred_name); | 86 CHECK_EQ(ref_inferred_name, *inferred_name); |
| 84 } | 87 } |
| 85 | 88 |
| 86 | 89 |
| 87 static v8::Handle<v8::Script> Compile(const char* src) { | 90 static v8::Handle<v8::Script> Compile(const char* src) { |
| 88 return v8::Script::Compile(v8::String::New(src)); | 91 return v8::Script::Compile(v8::String::New(src)); |
| 89 } | 92 } |
| 90 | 93 |
| 91 | 94 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 v8::HandleScope scope; | 244 v8::HandleScope scope; |
| 242 | 245 |
| 243 v8::Handle<v8::Script> script = Compile( | 246 v8::Handle<v8::Script> script = Compile( |
| 244 "function MyClass() {}\n" | 247 "function MyClass() {}\n" |
| 245 "MyClass.prototype = {\n" | 248 "MyClass.prototype = {\n" |
| 246 " method1: 0 ? function() { return 1; } :\n" | 249 " method1: 0 ? function() { return 1; } :\n" |
| 247 " function() { return 2; } }"); | 250 " function() { return 2; } }"); |
| 248 CheckFunctionName(script, "return 1", "MyClass.method1"); | 251 CheckFunctionName(script, "return 1", "MyClass.method1"); |
| 249 CheckFunctionName(script, "return 2", "MyClass.method1"); | 252 CheckFunctionName(script, "return 2", "MyClass.method1"); |
| 250 } | 253 } |
| OLD | NEW |