OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 // TODO(dcarney): remove |
| 29 #define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 30 #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 31 |
28 #include <v8.h> | 32 #include <v8.h> |
29 | 33 |
30 #ifdef ENABLE_DEBUGGER_SUPPORT | 34 #ifdef ENABLE_DEBUGGER_SUPPORT |
31 #include <v8-debug.h> | 35 #include <v8-debug.h> |
32 #endif // ENABLE_DEBUGGER_SUPPORT | 36 #endif // ENABLE_DEBUGGER_SUPPORT |
33 | 37 |
34 #include <fcntl.h> | 38 #include <fcntl.h> |
35 #include <string.h> | 39 #include <string.h> |
36 #include <stdio.h> | 40 #include <stdio.h> |
37 #include <stdlib.h> | 41 #include <stdlib.h> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // (we requested this when registered this callback). We was called | 121 // (we requested this when registered this callback). We was called |
118 // because new debug messages arrived; they may have already been processed, | 122 // because new debug messages arrived; they may have already been processed, |
119 // but we shouldn't worry about this. | 123 // but we shouldn't worry about this. |
120 // | 124 // |
121 // All we have to do is to set context and call ProcessDebugMessages. | 125 // All we have to do is to set context and call ProcessDebugMessages. |
122 // | 126 // |
123 // We should decide which V8 context to use here. This is important for | 127 // We should decide which V8 context to use here. This is important for |
124 // "evaluate" command, because it must be executed some context. | 128 // "evaluate" command, because it must be executed some context. |
125 // In our sample we have only one context, so there is nothing really to | 129 // In our sample we have only one context, so there is nothing really to |
126 // think about. | 130 // think about. |
127 v8::Context::Scope scope(debug_message_context); | 131 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 132 v8::HandleScope handle_scope(isolate); |
| 133 v8::Context::Scope scope(isolate, debug_message_context); |
128 | 134 |
129 v8::Debug::ProcessDebugMessages(); | 135 v8::Debug::ProcessDebugMessages(); |
130 } | 136 } |
131 #endif // ENABLE_DEBUGGER_SUPPORT | 137 #endif // ENABLE_DEBUGGER_SUPPORT |
132 | 138 |
133 | 139 |
134 int RunMain(int argc, char* argv[]) { | 140 int RunMain(int argc, char* argv[]) { |
135 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 141 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
136 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 142 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
137 v8::HandleScope handle_scope(isolate); | 143 v8::HandleScope handle_scope(isolate); |
138 | 144 |
139 v8::Handle<v8::String> script_source(NULL); | 145 v8::Handle<v8::String> script_source; |
140 v8::Handle<v8::Value> script_name(NULL); | 146 v8::Handle<v8::Value> script_name; |
141 int script_param_counter = 0; | 147 int script_param_counter = 0; |
142 | 148 |
143 #ifdef ENABLE_DEBUGGER_SUPPORT | 149 #ifdef ENABLE_DEBUGGER_SUPPORT |
144 int port_number = -1; | 150 int port_number = -1; |
145 bool wait_for_connection = false; | 151 bool wait_for_connection = false; |
146 bool support_callback = false; | 152 bool support_callback = false; |
147 #endif // ENABLE_DEBUGGER_SUPPORT | 153 #endif // ENABLE_DEBUGGER_SUPPORT |
148 | 154 |
149 MainCycleType cycle_type = CycleInCpp; | 155 MainCycleType cycle_type = CycleInCpp; |
150 | 156 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print)); | 208 global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print)); |
203 | 209 |
204 if (cycle_type == CycleInJs) { | 210 if (cycle_type == CycleInJs) { |
205 // Bind the global 'read_line' function to the C++ Print callback. | 211 // Bind the global 'read_line' function to the C++ Print callback. |
206 global->Set(v8::String::New("read_line"), | 212 global->Set(v8::String::New("read_line"), |
207 v8::FunctionTemplate::New(ReadLine)); | 213 v8::FunctionTemplate::New(ReadLine)); |
208 } | 214 } |
209 | 215 |
210 // Create a new execution environment containing the built-in | 216 // Create a new execution environment containing the built-in |
211 // functions | 217 // functions |
212 v8::Handle<v8::Context> context = v8::Context::New(NULL, global); | 218 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); |
213 // Enter the newly created execution environment. | 219 // Enter the newly created execution environment. |
214 v8::Context::Scope context_scope(context); | 220 v8::Context::Scope context_scope(context); |
215 | 221 |
216 #ifdef ENABLE_DEBUGGER_SUPPORT | 222 #ifdef ENABLE_DEBUGGER_SUPPORT |
217 debug_message_context = | 223 debug_message_context = |
218 v8::Persistent<v8::Context>::New(isolate, context); | 224 v8::Persistent<v8::Context>::New(isolate, context); |
219 | 225 |
220 v8::Locker locker(isolate); | 226 v8::Locker locker(isolate); |
221 | 227 |
222 if (support_callback) { | 228 if (support_callback) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 } | 441 } |
436 // Remove newline char | 442 // Remove newline char |
437 for (char* pos = buffer; *pos != '\0'; pos++) { | 443 for (char* pos = buffer; *pos != '\0'; pos++) { |
438 if (*pos == '\n') { | 444 if (*pos == '\n') { |
439 *pos = '\0'; | 445 *pos = '\0'; |
440 break; | 446 break; |
441 } | 447 } |
442 } | 448 } |
443 return v8::String::New(buffer); | 449 return v8::String::New(buffer); |
444 } | 450 } |
OLD | NEW |