| 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 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #ifdef COMPRESS_STARTUP_DATA_BZ2 | 34 #ifdef COMPRESS_STARTUP_DATA_BZ2 |
| 35 #include <bzlib.h> | 35 #include <bzlib.h> |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 #include <errno.h> | 38 #include <errno.h> |
| 39 #include <stdlib.h> | 39 #include <stdlib.h> |
| 40 #include <string.h> | 40 #include <string.h> |
| 41 #include <sys/stat.h> | 41 #include <sys/stat.h> |
| 42 | 42 |
| 43 // TODO(dcarney): remove |
| 44 #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 45 #define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 46 #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 47 |
| 43 #ifdef V8_SHARED | 48 #ifdef V8_SHARED |
| 44 #include <assert.h> | 49 #include <assert.h> |
| 45 #endif // V8_SHARED | 50 #endif // V8_SHARED |
| 46 | 51 |
| 47 #ifndef V8_SHARED | 52 #ifndef V8_SHARED |
| 48 #include <algorithm> | 53 #include <algorithm> |
| 49 #endif // !V8_SHARED | 54 #endif // !V8_SHARED |
| 50 | 55 |
| 51 #ifdef V8_SHARED | 56 #ifdef V8_SHARED |
| 52 #include "../include/v8-testing.h" | 57 #include "../include/v8-testing.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 FOR_EACH_STRING(DISPOSE_STRING) | 122 FOR_EACH_STRING(DISPOSE_STRING) |
| 118 #undef DISPOSE_STRING | 123 #undef DISPOSE_STRING |
| 119 isolate_->SetData(NULL); // Not really needed, just to be sure... | 124 isolate_->SetData(NULL); // Not really needed, just to be sure... |
| 120 } | 125 } |
| 121 | 126 |
| 122 inline static PerIsolateData* Get(Isolate* isolate) { | 127 inline static PerIsolateData* Get(Isolate* isolate) { |
| 123 return reinterpret_cast<PerIsolateData*>(isolate->GetData()); | 128 return reinterpret_cast<PerIsolateData*>(isolate->GetData()); |
| 124 } | 129 } |
| 125 | 130 |
| 126 #define DEFINE_STRING_GETTER(name, value) \ | 131 #define DEFINE_STRING_GETTER(name, value) \ |
| 127 static Persistent<String> name##_string(Isolate* isolate) { \ | 132 static Handle<String> name##_string(Isolate* isolate) { \ |
| 128 return Get(isolate)->name##_string_; \ | 133 return Handle<String>(*Get(isolate)->name##_string_); \ |
| 129 } | 134 } |
| 130 FOR_EACH_STRING(DEFINE_STRING_GETTER) | 135 FOR_EACH_STRING(DEFINE_STRING_GETTER) |
| 131 #undef DEFINE_STRING_GETTER | 136 #undef DEFINE_STRING_GETTER |
| 132 | 137 |
| 133 class RealmScope { | 138 class RealmScope { |
| 134 public: | 139 public: |
| 135 explicit RealmScope(PerIsolateData* data); | 140 explicit RealmScope(PerIsolateData* data); |
| 136 ~RealmScope(); | 141 ~RealmScope(); |
| 137 private: | 142 private: |
| 138 PerIsolateData* data_; | 143 PerIsolateData* data_; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 } | 243 } |
| 239 Handle<Script> script = Script::New(source, name); | 244 Handle<Script> script = Script::New(source, name); |
| 240 if (script.IsEmpty()) { | 245 if (script.IsEmpty()) { |
| 241 // Print errors that happened during compilation. | 246 // Print errors that happened during compilation. |
| 242 if (report_exceptions && !FLAG_debugger) | 247 if (report_exceptions && !FLAG_debugger) |
| 243 ReportException(isolate, &try_catch); | 248 ReportException(isolate, &try_catch); |
| 244 return false; | 249 return false; |
| 245 } else { | 250 } else { |
| 246 PerIsolateData* data = PerIsolateData::Get(isolate); | 251 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 247 Local<Context> realm = | 252 Local<Context> realm = |
| 248 Local<Context>::New(data->realms_[data->realm_current_]); | 253 Local<Context>::New(isolate, data->realms_[data->realm_current_]); |
| 249 realm->Enter(); | 254 realm->Enter(); |
| 250 Handle<Value> result = script->Run(); | 255 Handle<Value> result = script->Run(); |
| 251 realm->Exit(); | 256 realm->Exit(); |
| 252 data->realm_current_ = data->realm_switch_; | 257 data->realm_current_ = data->realm_switch_; |
| 253 if (result.IsEmpty()) { | 258 if (result.IsEmpty()) { |
| 254 ASSERT(try_catch.HasCaught()); | 259 ASSERT(try_catch.HasCaught()); |
| 255 // Print errors that happened during execution. | 260 // Print errors that happened during execution. |
| 256 if (report_exceptions && !FLAG_debugger) | 261 if (report_exceptions && !FLAG_debugger) |
| 257 ReportException(isolate, &try_catch); | 262 ReportException(isolate, &try_catch); |
| 258 return false; | 263 return false; |
| 259 } else { | 264 } else { |
| 260 ASSERT(!try_catch.HasCaught()); | 265 ASSERT(!try_catch.HasCaught()); |
| 261 if (print_result) { | 266 if (print_result) { |
| 262 #if !defined(V8_SHARED) | 267 #if !defined(V8_SHARED) |
| 263 if (options.test_shell) { | 268 if (options.test_shell) { |
| 264 #endif | 269 #endif |
| 265 if (!result->IsUndefined()) { | 270 if (!result->IsUndefined()) { |
| 266 // If all went well and the result wasn't undefined then print | 271 // If all went well and the result wasn't undefined then print |
| 267 // the returned value. | 272 // the returned value. |
| 268 v8::String::Utf8Value str(result); | 273 v8::String::Utf8Value str(result); |
| 269 fwrite(*str, sizeof(**str), str.length(), stdout); | 274 fwrite(*str, sizeof(**str), str.length(), stdout); |
| 270 printf("\n"); | 275 printf("\n"); |
| 271 } | 276 } |
| 272 #if !defined(V8_SHARED) | 277 #if !defined(V8_SHARED) |
| 273 } else { | 278 } else { |
| 274 v8::TryCatch try_catch; | 279 v8::TryCatch try_catch; |
| 275 Context::Scope context_scope(utility_context_); | 280 Context::Scope context_scope(isolate, utility_context_); |
| 276 Handle<Object> global = utility_context_->Global(); | 281 Handle<Object> global = utility_context_->Global(); |
| 277 Handle<Value> fun = global->Get(String::New("Stringify")); | 282 Handle<Value> fun = global->Get(String::New("Stringify")); |
| 278 Handle<Value> argv[1] = { result }; | 283 Handle<Value> argv[1] = { result }; |
| 279 Handle<Value> s = Handle<Function>::Cast(fun)->Call(global, 1, argv); | 284 Handle<Value> s = Handle<Function>::Cast(fun)->Call(global, 1, argv); |
| 280 if (try_catch.HasCaught()) return true; | 285 if (try_catch.HasCaught()) return true; |
| 281 v8::String::Utf8Value str(s); | 286 v8::String::Utf8Value str(s); |
| 282 fwrite(*str, sizeof(**str), str.length(), stdout); | 287 fwrite(*str, sizeof(**str), str.length(), stdout); |
| 283 printf("\n"); | 288 printf("\n"); |
| 284 } | 289 } |
| 285 #endif | 290 #endif |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 PerIsolateData* data = PerIsolateData::Get(isolate); | 419 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 415 if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsString()) { | 420 if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsString()) { |
| 416 return Throw("Invalid argument"); | 421 return Throw("Invalid argument"); |
| 417 } | 422 } |
| 418 int index = args[0]->Uint32Value(); | 423 int index = args[0]->Uint32Value(); |
| 419 if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) { | 424 if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) { |
| 420 return Throw("Invalid realm index"); | 425 return Throw("Invalid realm index"); |
| 421 } | 426 } |
| 422 Handle<Script> script = Script::New(args[1]->ToString()); | 427 Handle<Script> script = Script::New(args[1]->ToString()); |
| 423 if (script.IsEmpty()) return Undefined(isolate); | 428 if (script.IsEmpty()) return Undefined(isolate); |
| 424 Local<Context> realm = Local<Context>::New(data->realms_[index]); | 429 Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]); |
| 425 realm->Enter(); | 430 realm->Enter(); |
| 426 Handle<Value> result = script->Run(); | 431 Handle<Value> result = script->Run(); |
| 427 realm->Exit(); | 432 realm->Exit(); |
| 428 return result; | 433 return result; |
| 429 } | 434 } |
| 430 | 435 |
| 431 | 436 |
| 432 // Realm.shared is an accessor for a single shared value across realms. | 437 // Realm.shared is an accessor for a single shared value across realms. |
| 433 Handle<Value> Shell::RealmSharedGet(Local<String> property, | 438 Handle<Value> Shell::RealmSharedGet(Local<String> property, |
| 434 const AccessorInfo& info) { | 439 const AccessorInfo& info) { |
| 435 Isolate* isolate = info.GetIsolate(); | 440 Isolate* isolate = info.GetIsolate(); |
| 436 PerIsolateData* data = PerIsolateData::Get(isolate); | 441 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 437 if (data->realm_shared_.IsEmpty()) return Undefined(isolate); | 442 if (data->realm_shared_.IsEmpty()) return Undefined(isolate); |
| 438 return data->realm_shared_; | 443 return Local<Value>::New(isolate, data->realm_shared_); |
| 439 } | 444 } |
| 440 | 445 |
| 441 void Shell::RealmSharedSet(Local<String> property, | 446 void Shell::RealmSharedSet(Local<String> property, |
| 442 Local<Value> value, | 447 Local<Value> value, |
| 443 const AccessorInfo& info) { | 448 const AccessorInfo& info) { |
| 444 Isolate* isolate = info.GetIsolate(); | 449 Isolate* isolate = info.GetIsolate(); |
| 445 PerIsolateData* data = PerIsolateData::Get(isolate); | 450 PerIsolateData* data = PerIsolateData::Get(isolate); |
| 446 if (!data->realm_shared_.IsEmpty()) data->realm_shared_.Dispose(isolate); | 451 if (!data->realm_shared_.IsEmpty()) data->realm_shared_.Dispose(isolate); |
| 447 data->realm_shared_ = Persistent<Value>::New(isolate, value); | 452 data->realm_shared_ = Persistent<Value>::New(isolate, value); |
| 448 } | 453 } |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 if (enter_context) utility_context_->Exit(); | 1178 if (enter_context) utility_context_->Exit(); |
| 1174 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 1179 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
| 1175 } | 1180 } |
| 1176 | 1181 |
| 1177 | 1182 |
| 1178 #ifndef V8_SHARED | 1183 #ifndef V8_SHARED |
| 1179 Handle<Array> Shell::GetCompletions(Isolate* isolate, | 1184 Handle<Array> Shell::GetCompletions(Isolate* isolate, |
| 1180 Handle<String> text, | 1185 Handle<String> text, |
| 1181 Handle<String> full) { | 1186 Handle<String> full) { |
| 1182 HandleScope handle_scope(isolate); | 1187 HandleScope handle_scope(isolate); |
| 1183 Context::Scope context_scope(utility_context_); | 1188 Context::Scope context_scope(isolate, utility_context_); |
| 1184 Handle<Object> global = utility_context_->Global(); | 1189 Handle<Object> global = utility_context_->Global(); |
| 1185 Handle<Value> fun = global->Get(String::New("GetCompletions")); | 1190 Handle<Value> fun = global->Get(String::New("GetCompletions")); |
| 1186 static const int kArgc = 3; | 1191 static const int kArgc = 3; |
| 1187 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; | 1192 Handle<Value> argv[kArgc] = { evaluation_context_->Global(), text, full }; |
| 1188 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); | 1193 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |
| 1189 return handle_scope.Close(Handle<Array>::Cast(val)); | 1194 return handle_scope.Close(Handle<Array>::Cast(val)); |
| 1190 } | 1195 } |
| 1191 | 1196 |
| 1192 | 1197 |
| 1193 #ifdef ENABLE_DEBUGGER_SUPPORT | 1198 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1194 Handle<Object> Shell::DebugMessageDetails(Handle<String> message) { | 1199 Handle<Object> Shell::DebugMessageDetails(Isolate* isolate, |
| 1195 Context::Scope context_scope(utility_context_); | 1200 Handle<String> message) { |
| 1201 HandleScope handle_scope(isolate); |
| 1202 Context::Scope context_scope(isolate, utility_context_); |
| 1196 Handle<Object> global = utility_context_->Global(); | 1203 Handle<Object> global = utility_context_->Global(); |
| 1197 Handle<Value> fun = global->Get(String::New("DebugMessageDetails")); | 1204 Handle<Value> fun = global->Get(String::New("DebugMessageDetails")); |
| 1198 static const int kArgc = 1; | 1205 static const int kArgc = 1; |
| 1199 Handle<Value> argv[kArgc] = { message }; | 1206 Handle<Value> argv[kArgc] = { message }; |
| 1200 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); | 1207 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |
| 1201 return Handle<Object>::Cast(val); | 1208 return Handle<Object>::Cast(val); |
| 1202 } | 1209 } |
| 1203 | 1210 |
| 1204 | 1211 |
| 1205 Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) { | 1212 Handle<Value> Shell::DebugCommandToJSONRequest(Isolate* isolate, |
| 1206 Context::Scope context_scope(utility_context_); | 1213 Handle<String> command) { |
| 1214 HandleScope handle_scope(isolate); |
| 1215 Context::Scope context_scope(isolate, utility_context_); |
| 1207 Handle<Object> global = utility_context_->Global(); | 1216 Handle<Object> global = utility_context_->Global(); |
| 1208 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); | 1217 Handle<Value> fun = global->Get(String::New("DebugCommandToJSONRequest")); |
| 1209 static const int kArgc = 1; | 1218 static const int kArgc = 1; |
| 1210 Handle<Value> argv[kArgc] = { command }; | 1219 Handle<Value> argv[kArgc] = { command }; |
| 1211 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); | 1220 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); |
| 1212 return val; | 1221 return val; |
| 1213 } | 1222 } |
| 1214 | 1223 |
| 1215 | 1224 |
| 1216 void Shell::DispatchDebugMessages() { | 1225 void Shell::DispatchDebugMessages() { |
| 1217 v8::Context::Scope scope(Shell::evaluation_context_); | 1226 Isolate* isolate = v8::Isolate::GetCurrent(); |
| 1227 HandleScope handle_scope(isolate); |
| 1228 v8::Context::Scope scope(isolate, Shell::evaluation_context_); |
| 1218 v8::Debug::ProcessDebugMessages(); | 1229 v8::Debug::ProcessDebugMessages(); |
| 1219 } | 1230 } |
| 1220 #endif // ENABLE_DEBUGGER_SUPPORT | 1231 #endif // ENABLE_DEBUGGER_SUPPORT |
| 1221 #endif // V8_SHARED | 1232 #endif // V8_SHARED |
| 1222 | 1233 |
| 1223 | 1234 |
| 1224 #ifndef V8_SHARED | 1235 #ifndef V8_SHARED |
| 1225 int32_t* Counter::Bind(const char* name, bool is_histogram) { | 1236 int32_t* Counter::Bind(const char* name, bool is_histogram) { |
| 1226 int i; | 1237 int i; |
| 1227 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) | 1238 for (i = 0; i < kMaxNameSize - 1 && name[i]; i++) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 } | 1331 } |
| 1321 | 1332 |
| 1322 | 1333 |
| 1323 void Shell::InstallUtilityScript(Isolate* isolate) { | 1334 void Shell::InstallUtilityScript(Isolate* isolate) { |
| 1324 Locker lock(isolate); | 1335 Locker lock(isolate); |
| 1325 HandleScope scope(isolate); | 1336 HandleScope scope(isolate); |
| 1326 // If we use the utility context, we have to set the security tokens so that | 1337 // If we use the utility context, we have to set the security tokens so that |
| 1327 // utility, evaluation and debug context can all access each other. | 1338 // utility, evaluation and debug context can all access each other. |
| 1328 utility_context_->SetSecurityToken(Undefined(isolate)); | 1339 utility_context_->SetSecurityToken(Undefined(isolate)); |
| 1329 evaluation_context_->SetSecurityToken(Undefined(isolate)); | 1340 evaluation_context_->SetSecurityToken(Undefined(isolate)); |
| 1330 Context::Scope utility_scope(utility_context_); | 1341 Context::Scope utility_scope(isolate, utility_context_); |
| 1331 | 1342 |
| 1332 #ifdef ENABLE_DEBUGGER_SUPPORT | 1343 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1333 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); | 1344 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); |
| 1334 // Install the debugger object in the utility scope | 1345 // Install the debugger object in the utility scope |
| 1335 i::Debug* debug = i::Isolate::Current()->debug(); | 1346 i::Debug* debug = i::Isolate::Current()->debug(); |
| 1336 debug->Load(); | 1347 debug->Load(); |
| 1337 i::Handle<i::JSObject> js_debug | 1348 i::Handle<i::JSObject> js_debug |
| 1338 = i::Handle<i::JSObject>(debug->debug_context()->global_object()); | 1349 = i::Handle<i::JSObject>(debug->debug_context()->global_object()); |
| 1339 utility_context_->Global()->Set(String::New("$debug"), | 1350 utility_context_->Global()->Set(String::New("$debug"), |
| 1340 Utils::ToLocal(js_debug)); | 1351 Utils::ToLocal(js_debug)); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 | 1554 |
| 1544 Persistent<Context> Shell::CreateEvaluationContext(Isolate* isolate) { | 1555 Persistent<Context> Shell::CreateEvaluationContext(Isolate* isolate) { |
| 1545 #ifndef V8_SHARED | 1556 #ifndef V8_SHARED |
| 1546 // This needs to be a critical section since this is not thread-safe | 1557 // This needs to be a critical section since this is not thread-safe |
| 1547 i::ScopedLock lock(context_mutex_); | 1558 i::ScopedLock lock(context_mutex_); |
| 1548 #endif // V8_SHARED | 1559 #endif // V8_SHARED |
| 1549 // Initialize the global objects | 1560 // Initialize the global objects |
| 1550 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); | 1561 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); |
| 1551 Persistent<Context> context = Context::New(NULL, global_template); | 1562 Persistent<Context> context = Context::New(NULL, global_template); |
| 1552 ASSERT(!context.IsEmpty()); | 1563 ASSERT(!context.IsEmpty()); |
| 1553 Context::Scope scope(context); | 1564 HandleScope handle_scope(isolate); |
| 1565 Context::Scope scope(isolate, context); |
| 1554 | 1566 |
| 1555 #ifndef V8_SHARED | 1567 #ifndef V8_SHARED |
| 1556 i::JSArguments js_args = i::FLAG_js_arguments; | 1568 i::JSArguments js_args = i::FLAG_js_arguments; |
| 1557 i::Handle<i::FixedArray> arguments_array = | 1569 i::Handle<i::FixedArray> arguments_array = |
| 1558 FACTORY->NewFixedArray(js_args.argc()); | 1570 FACTORY->NewFixedArray(js_args.argc()); |
| 1559 for (int j = 0; j < js_args.argc(); j++) { | 1571 for (int j = 0; j < js_args.argc(); j++) { |
| 1560 i::Handle<i::String> arg = | 1572 i::Handle<i::String> arg = |
| 1561 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); | 1573 FACTORY->NewStringFromUtf8(i::CStrVector(js_args[j])); |
| 1562 arguments_array->set(j, *arg); | 1574 arguments_array->set(j, *arg); |
| 1563 } | 1575 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 | 1735 |
| 1724 | 1736 |
| 1725 static char* ReadLine(char* data) { | 1737 static char* ReadLine(char* data) { |
| 1726 return ReadToken(data, '\n'); | 1738 return ReadToken(data, '\n'); |
| 1727 } | 1739 } |
| 1728 | 1740 |
| 1729 | 1741 |
| 1730 static char* ReadWord(char* data) { | 1742 static char* ReadWord(char* data) { |
| 1731 return ReadToken(data, ' '); | 1743 return ReadToken(data, ' '); |
| 1732 } | 1744 } |
| 1733 #endif // trueV8_SHARED | 1745 #endif // V8_SHARED |
| 1734 | 1746 |
| 1735 | 1747 |
| 1736 // Reads a file into a v8 string. | 1748 // Reads a file into a v8 string. |
| 1737 Handle<String> Shell::ReadFile(Isolate* isolate, const char* name) { | 1749 Handle<String> Shell::ReadFile(Isolate* isolate, const char* name) { |
| 1738 int size = 0; | 1750 int size = 0; |
| 1739 char* chars = ReadChars(isolate, name, &size); | 1751 char* chars = ReadChars(isolate, name, &size); |
| 1740 if (chars == NULL) return Handle<String>(); | 1752 if (chars == NULL) return Handle<String>(); |
| 1741 Handle<String> result = String::New(chars, size); | 1753 Handle<String> result = String::New(chars, size); |
| 1742 delete[] chars; | 1754 delete[] chars; |
| 1743 return result; | 1755 return result; |
| 1744 } | 1756 } |
| 1745 | 1757 |
| 1746 | 1758 |
| 1747 void Shell::RunShell(Isolate* isolate) { | 1759 void Shell::RunShell(Isolate* isolate) { |
| 1748 Locker locker(isolate); | 1760 Locker locker(isolate); |
| 1749 Context::Scope context_scope(evaluation_context_); | 1761 Context::Scope context_scope(isolate, evaluation_context_); |
| 1750 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); | 1762 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); |
| 1751 HandleScope outer_scope(isolate); | 1763 HandleScope outer_scope(isolate); |
| 1752 Handle<String> name = String::New("(d8)"); | 1764 Handle<String> name = String::New("(d8)"); |
| 1753 LineEditor* console = LineEditor::Get(); | 1765 LineEditor* console = LineEditor::Get(); |
| 1754 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); | 1766 printf("V8 version %s [console: %s]\n", V8::GetVersion(), console->name()); |
| 1755 console->Open(isolate); | 1767 console->Open(isolate); |
| 1756 while (true) { | 1768 while (true) { |
| 1757 HandleScope inner_scope(isolate); | 1769 HandleScope inner_scope(isolate); |
| 1758 Handle<String> input = console->Prompt(Shell::kPrompt); | 1770 Handle<String> input = console->Prompt(Shell::kPrompt); |
| 1759 if (input.IsEmpty()) break; | 1771 if (input.IsEmpty()) break; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1792 // Skip comment lines. | 1804 // Skip comment lines. |
| 1793 ptr = next_line; | 1805 ptr = next_line; |
| 1794 continue; | 1806 continue; |
| 1795 } | 1807 } |
| 1796 | 1808 |
| 1797 // Prepare the context for this thread. | 1809 // Prepare the context for this thread. |
| 1798 Locker locker(isolate_); | 1810 Locker locker(isolate_); |
| 1799 HandleScope outer_scope(isolate_); | 1811 HandleScope outer_scope(isolate_); |
| 1800 Persistent<Context> thread_context = | 1812 Persistent<Context> thread_context = |
| 1801 Shell::CreateEvaluationContext(isolate_); | 1813 Shell::CreateEvaluationContext(isolate_); |
| 1802 Context::Scope context_scope(thread_context); | 1814 Context::Scope context_scope(isolate_, thread_context); |
| 1803 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate_)); | 1815 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate_)); |
| 1804 | 1816 |
| 1805 while ((ptr != NULL) && (*ptr != '\0')) { | 1817 while ((ptr != NULL) && (*ptr != '\0')) { |
| 1806 HandleScope inner_scope(isolate_); | 1818 HandleScope inner_scope(isolate_); |
| 1807 char* filename = ptr; | 1819 char* filename = ptr; |
| 1808 ptr = ReadWord(ptr); | 1820 ptr = ReadWord(ptr); |
| 1809 | 1821 |
| 1810 // Skip empty strings. | 1822 // Skip empty strings. |
| 1811 if (strlen(filename) == 0) { | 1823 if (strlen(filename) == 0) { |
| 1812 continue; | 1824 continue; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1895 Isolate* isolate = Isolate::New(); | 1907 Isolate* isolate = Isolate::New(); |
| 1896 do { | 1908 do { |
| 1897 if (next_semaphore_ != NULL) next_semaphore_->Wait(); | 1909 if (next_semaphore_ != NULL) next_semaphore_->Wait(); |
| 1898 { | 1910 { |
| 1899 Isolate::Scope iscope(isolate); | 1911 Isolate::Scope iscope(isolate); |
| 1900 Locker lock(isolate); | 1912 Locker lock(isolate); |
| 1901 HandleScope scope(isolate); | 1913 HandleScope scope(isolate); |
| 1902 PerIsolateData data(isolate); | 1914 PerIsolateData data(isolate); |
| 1903 Persistent<Context> context = Shell::CreateEvaluationContext(isolate); | 1915 Persistent<Context> context = Shell::CreateEvaluationContext(isolate); |
| 1904 { | 1916 { |
| 1905 Context::Scope cscope(context); | 1917 Context::Scope cscope(isolate, context); |
| 1906 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); | 1918 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); |
| 1907 Execute(isolate); | 1919 Execute(isolate); |
| 1908 } | 1920 } |
| 1909 context.Dispose(isolate); | 1921 context.Dispose(isolate); |
| 1910 if (Shell::options.send_idle_notification) { | 1922 if (Shell::options.send_idle_notification) { |
| 1911 const int kLongIdlePauseInMs = 1000; | 1923 const int kLongIdlePauseInMs = 1000; |
| 1912 V8::ContextDisposedNotification(); | 1924 V8::ContextDisposedNotification(); |
| 1913 V8::IdleNotification(kLongIdlePauseInMs); | 1925 V8::IdleNotification(kLongIdlePauseInMs); |
| 1914 } | 1926 } |
| 1915 } | 1927 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2104 evaluation_context_ = context; | 2116 evaluation_context_ = context; |
| 2105 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) | 2117 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) |
| 2106 // If the interactive debugger is enabled make sure to activate | 2118 // If the interactive debugger is enabled make sure to activate |
| 2107 // it before running the files passed on the command line. | 2119 // it before running the files passed on the command line. |
| 2108 if (i::FLAG_debugger) { | 2120 if (i::FLAG_debugger) { |
| 2109 InstallUtilityScript(isolate); | 2121 InstallUtilityScript(isolate); |
| 2110 } | 2122 } |
| 2111 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT | 2123 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT |
| 2112 } | 2124 } |
| 2113 { | 2125 { |
| 2114 Context::Scope cscope(context); | 2126 Context::Scope cscope(isolate, context); |
| 2115 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); | 2127 PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate)); |
| 2116 options.isolate_sources[0].Execute(isolate); | 2128 options.isolate_sources[0].Execute(isolate); |
| 2117 } | 2129 } |
| 2118 if (!options.last_run) { | 2130 if (!options.last_run) { |
| 2119 context.Dispose(isolate); | 2131 context.Dispose(isolate); |
| 2120 if (options.send_idle_notification) { | 2132 if (options.send_idle_notification) { |
| 2121 const int kLongIdlePauseInMs = 1000; | 2133 const int kLongIdlePauseInMs = 1000; |
| 2122 V8::ContextDisposedNotification(); | 2134 V8::ContextDisposedNotification(); |
| 2123 V8::IdleNotification(kLongIdlePauseInMs); | 2135 V8::IdleNotification(kLongIdlePauseInMs); |
| 2124 } | 2136 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2223 } | 2235 } |
| 2224 | 2236 |
| 2225 } // namespace v8 | 2237 } // namespace v8 |
| 2226 | 2238 |
| 2227 | 2239 |
| 2228 #ifndef GOOGLE3 | 2240 #ifndef GOOGLE3 |
| 2229 int main(int argc, char* argv[]) { | 2241 int main(int argc, char* argv[]) { |
| 2230 return v8::Shell::Main(argc, argv); | 2242 return v8::Shell::Main(argc, argv); |
| 2231 } | 2243 } |
| 2232 #endif | 2244 #endif |
| OLD | NEW |