Permalink
Browse files

Added a version of the v8::HandleScope constructor with an Isolate an…

…d use that consistently.

I tried to limit the use of v8::Isolate::GetCurrent() and v8::internal::Isolate::Current() as much as possible, but sometimes this would have involved restructuring tests quite a bit, which is better left for a separate CL.

BUG=v8:2487

Review URL: https://codereview.chromium.org/12716010

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@13953 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
  • Loading branch information...
1 parent 97b98f3 commit 82809d095eaba256e968516ce410eebac67f903e svenpanne@chromium.org committed Mar 15, 2013
Showing with 1,239 additions and 1,179 deletions.
  1. +4 −0 include/v8.h
  2. +21 −17 samples/lineprocessor.cc
  3. +27 −22 samples/process.cc
  4. +31 −20 samples/shell.cc
  5. +27 −18 src/api.cc
  6. +17 −15 src/d8-debug.cc
  7. +5 −3 src/d8-debug.h
  8. +1 −1 src/d8-posix.cc
  9. +1 −1 src/d8-readline.cc
  10. +35 −28 src/d8.cc
  11. +5 −3 src/d8.h
  12. +2 −1 src/debug.cc
  13. +5 −3 src/factory.cc
  14. +3 −2 src/mksnapshot.cc
  15. +23 −23 test/cctest/test-accessors.cc
  16. +2 −2 test/cctest/test-alloc.cc
  17. +488 −492 test/cctest/test-api.cc
  18. +29 −28 test/cctest/test-assembler-arm.cc
  19. +22 −22 test/cctest/test-assembler-ia32.cc
  20. +48 −32 test/cctest/test-assembler-mips.cc
  21. +3 −2 test/cctest/test-assembler-x64.cc
  22. +13 −15 test/cctest/test-compiler.cc
  23. +3 −3 test/cctest/test-cpu-profiler.cc
  24. +3 −3 test/cctest/test-date.cc
  25. +116 −114 test/cctest/test-debug.cc
  26. +6 −7 test/cctest/test-declarative-accessors.cc
  27. +14 −14 test/cctest/test-decls.cc
  28. +16 −16 test/cctest/test-deoptimization.cc
  29. +3 −3 test/cctest/test-dictionary.cc
  30. +4 −3 test/cctest/test-disasm-arm.cc
  31. +5 −7 test/cctest/test-disasm-ia32.cc
  32. +4 −3 test/cctest/test-disasm-mips.cc
  33. +21 −23 test/cctest/test-func-name-inference.cc
  34. +1 −1 test/cctest/test-global-object.cc
  35. +43 −43 test/cctest/test-heap-profiler.cc
  36. +86 −84 test/cctest/test-heap.cc
  37. +20 −20 test/cctest/test-lockers.cc
  38. +4 −6 test/cctest/test-log-stack-tracer.cc
  39. +2 −2 test/cctest/test-log.cc
  40. +5 −6 test/cctest/test-mark-compact.cc
  41. +12 −10 test/cctest/test-object-observe.cc
  42. +6 −6 test/cctest/test-parsing.cc
  43. +4 −4 test/cctest/test-profile-generator.cc
  44. +1 −1 test/cctest/test-random.cc
  45. +9 −8 test/cctest/test-regexp.cc
  46. +8 −8 test/cctest/test-serialize.cc
  47. +13 −14 test/cctest/test-strings.cc
  48. +0 −2 test/cctest/test-symbols.cc
  49. +6 −6 test/cctest/test-thread-termination.cc
  50. +3 −3 test/cctest/test-threads.cc
  51. +9 −9 test/cctest/test-weakmaps.cc
View
@@ -514,8 +514,11 @@ template <class T> class Persistent : public Handle<T> {
*/
class V8EXPORT HandleScope {
public:
+ // TODO(svenpanne) Deprecate me when Chrome is fixed!
HandleScope();
+ HandleScope(Isolate* isolate);
+
~HandleScope();
/**
@@ -559,6 +562,7 @@ class V8EXPORT HandleScope {
}
};
+ void Initialize(Isolate* isolate);
void Leave();
internal::Isolate* isolate_;
View
@@ -98,13 +98,14 @@ enum MainCycleType {
};
const char* ToCString(const v8::String::Utf8Value& value);
-void ReportException(v8::TryCatch* handler);
+void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);
v8::Handle<v8::String> ReadFile(const char* name);
v8::Handle<v8::String> ReadLine();
v8::Handle<v8::Value> Print(const v8::Arguments& args);
v8::Handle<v8::Value> ReadLine(const v8::Arguments& args);
-bool RunCppCycle(v8::Handle<v8::Script> script, v8::Local<v8::Context> context,
+bool RunCppCycle(v8::Handle<v8::Script> script,
+ v8::Local<v8::Context> context,
bool report_exceptions);
@@ -132,7 +133,8 @@ void DispatchDebugMessages() {
int RunMain(int argc, char* argv[]) {
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
- v8::HandleScope handle_scope;
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::HandleScope handle_scope(isolate);
v8::Handle<v8::String> script_source(NULL);
v8::Handle<v8::Value> script_name(NULL);
@@ -213,9 +215,9 @@ int RunMain(int argc, char* argv[]) {
#ifdef ENABLE_DEBUGGER_SUPPORT
debug_message_context =
- v8::Persistent<v8::Context>::New(context->GetIsolate(), context);
+ v8::Persistent<v8::Context>::New(isolate, context);
- v8::Locker locker(context->GetIsolate());
+ v8::Locker locker(isolate);
if (support_callback) {
v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true);
@@ -236,7 +238,7 @@ int RunMain(int argc, char* argv[]) {
if (script.IsEmpty()) {
// Print errors that happened during compilation.
if (report_exceptions)
- ReportException(&try_catch);
+ ReportException(isolate, &try_catch);
return 1;
}
}
@@ -247,13 +249,14 @@ int RunMain(int argc, char* argv[]) {
script->Run();
if (try_catch.HasCaught()) {
if (report_exceptions)
- ReportException(&try_catch);
+ ReportException(isolate, &try_catch);
return 1;
}
}
if (cycle_type == CycleInCpp) {
- bool res = RunCppCycle(script, v8::Context::GetCurrent(),
+ bool res = RunCppCycle(script,
+ v8::Context::GetCurrent(),
report_exceptions);
return !res;
} else {
@@ -263,15 +266,16 @@ int RunMain(int argc, char* argv[]) {
}
-bool RunCppCycle(v8::Handle<v8::Script> script, v8::Local<v8::Context> context,
+bool RunCppCycle(v8::Handle<v8::Script> script,
+ v8::Local<v8::Context> context,
bool report_exceptions) {
+ v8::Isolate* isolate = context->GetIsolate();
#ifdef ENABLE_DEBUGGER_SUPPORT
- v8::Locker lock(v8::Isolate::GetCurrent());
+ v8::Locker lock(isolate);
#endif // ENABLE_DEBUGGER_SUPPORT
v8::Handle<v8::String> fun_name = v8::String::New("ProcessLine");
- v8::Handle<v8::Value> process_val =
- v8::Context::GetCurrent()->Global()->Get(fun_name);
+ v8::Handle<v8::Value> process_val = context->Global()->Get(fun_name);
// If there is no Process function, or if it is not a function,
// bail out
@@ -286,7 +290,7 @@ bool RunCppCycle(v8::Handle<v8::Script> script, v8::Local<v8::Context> context,
while (!feof(stdin)) {
- v8::HandleScope handle_scope;
+ v8::HandleScope handle_scope(isolate);
v8::Handle<v8::String> input_line = ReadLine();
if (input_line == v8::Undefined()) {
@@ -303,7 +307,7 @@ bool RunCppCycle(v8::Handle<v8::Script> script, v8::Local<v8::Context> context,
argc, argv);
if (try_catch.HasCaught()) {
if (report_exceptions)
- ReportException(&try_catch);
+ ReportException(isolate, &try_catch);
return false;
}
}
@@ -350,8 +354,8 @@ v8::Handle<v8::String> ReadFile(const char* name) {
}
-void ReportException(v8::TryCatch* try_catch) {
- v8::HandleScope handle_scope;
+void ReportException(v8::Isolate* isolate, v8::TryCatch* try_catch) {
+ v8::HandleScope handle_scope(isolate);
v8::String::Utf8Value exception(try_catch->Exception());
const char* exception_string = ToCString(exception);
v8::Handle<v8::Message> message = try_catch->Message();
@@ -389,7 +393,7 @@ void ReportException(v8::TryCatch* try_catch) {
v8::Handle<v8::Value> Print(const v8::Arguments& args) {
bool first = true;
for (int i = 0; i < args.Length(); i++) {
- v8::HandleScope handle_scope;
+ v8::HandleScope handle_scope(args.GetIsolate());
if (first) {
first = false;
} else {
View
@@ -79,7 +79,8 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
public:
// Creates a new processor that processes requests by invoking the
// Process function of the JavaScript script given as an argument.
- explicit JsHttpRequestProcessor(Handle<String> script) : script_(script) { }
+ JsHttpRequestProcessor(Isolate* isolate, Handle<String> script)
+ : isolate_(isolate), script_(script) { }
virtual ~JsHttpRequestProcessor();
virtual bool Initialize(map<string, string>* opts,
@@ -97,8 +98,8 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
// Constructs the template that describes the JavaScript wrapper
// type for requests.
- static Handle<ObjectTemplate> MakeRequestTemplate();
- static Handle<ObjectTemplate> MakeMapTemplate();
+ static Handle<ObjectTemplate> MakeRequestTemplate(Isolate* isolate);
+ static Handle<ObjectTemplate> MakeMapTemplate(Isolate* isolate);
// Callbacks that access the individual fields of request objects.
static Handle<Value> GetPath(Local<String> name, const AccessorInfo& info);
@@ -121,8 +122,9 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
Handle<Object> WrapRequest(HttpRequest* obj);
static HttpRequest* UnwrapRequest(Handle<Object> obj);
- Isolate* GetIsolate() { return context_->GetIsolate(); }
+ Isolate* GetIsolate() { return isolate_; }
+ Isolate* isolate_;
Handle<String> script_;
Persistent<Context> context_;
Persistent<Function> process_;
@@ -136,20 +138,20 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
static Handle<Value> LogCallback(const Arguments& args) {
- if (args.Length() < 1) return v8::Undefined();
- HandleScope scope;
+ if (args.Length() < 1) return Undefined();
+ HandleScope scope(args.GetIsolate());
Handle<Value> arg = args[0];
String::Utf8Value value(arg);
HttpRequestProcessor::Log(*value);
- return v8::Undefined();
+ return Undefined();
}
// Execute the script and fetch the Process method.
bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
map<string, string>* output) {
// Create a handle scope to hold the temporary references.
- HandleScope handle_scope;
+ HandleScope handle_scope(GetIsolate());
// Create a template for the global object where we set the
// built-in global functions.
@@ -197,7 +199,7 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
bool JsHttpRequestProcessor::ExecuteScript(Handle<String> script) {
- HandleScope handle_scope;
+ HandleScope handle_scope(GetIsolate());
// We're just about to compile the script; set up an error handler to
// catch any exceptions the script might throw.
@@ -227,7 +229,7 @@ bool JsHttpRequestProcessor::ExecuteScript(Handle<String> script) {
bool JsHttpRequestProcessor::InstallMaps(map<string, string>* opts,
map<string, string>* output) {
- HandleScope handle_scope;
+ HandleScope handle_scope(GetIsolate());
// Wrap the map object in a JavaScript wrapper
Handle<Object> opts_obj = WrapMap(opts);
@@ -244,7 +246,7 @@ bool JsHttpRequestProcessor::InstallMaps(map<string, string>* opts,
bool JsHttpRequestProcessor::Process(HttpRequest* request) {
// Create a handle scope to keep the temporary object references.
- HandleScope handle_scope;
+ HandleScope handle_scope(GetIsolate());
// Enter this processor's context so all the remaining operations
// take place there
@@ -275,7 +277,7 @@ JsHttpRequestProcessor::~JsHttpRequestProcessor() {
// Dispose the persistent handles. When noone else has any
// references to the objects stored in the handles they will be
// automatically reclaimed.
- v8::Isolate* isolate = GetIsolate();
+ Isolate* isolate = GetIsolate();
context_.Dispose(isolate);
process_.Dispose(isolate);
}
@@ -293,12 +295,12 @@ Persistent<ObjectTemplate> JsHttpRequestProcessor::map_template_;
// JavaScript object.
Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) {
// Handle scope for temporary handles.
- HandleScope handle_scope;
+ HandleScope handle_scope(GetIsolate());
// Fetch the template for creating JavaScript map wrappers.
// It only has to be created once, which we do on demand.
if (map_template_.IsEmpty()) {
- Handle<ObjectTemplate> raw_template = MakeMapTemplate();
+ Handle<ObjectTemplate> raw_template = MakeMapTemplate(GetIsolate());
map_template_ = Persistent<ObjectTemplate>::New(GetIsolate(), raw_template);
}
Handle<ObjectTemplate> templ = map_template_;
@@ -376,8 +378,9 @@ Handle<Value> JsHttpRequestProcessor::MapSet(Local<String> name,
}
-Handle<ObjectTemplate> JsHttpRequestProcessor::MakeMapTemplate() {
- HandleScope handle_scope;
+Handle<ObjectTemplate> JsHttpRequestProcessor::MakeMapTemplate(
+ Isolate* isolate) {
+ HandleScope handle_scope(isolate);
Handle<ObjectTemplate> result = ObjectTemplate::New();
result->SetInternalFieldCount(1);
@@ -398,12 +401,12 @@ Handle<ObjectTemplate> JsHttpRequestProcessor::MakeMapTemplate() {
*/
Handle<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) {
// Handle scope for temporary handles.
- HandleScope handle_scope;
+ HandleScope handle_scope(GetIsolate());
// Fetch the template for creating JavaScript http request wrappers.
// It only has to be created once, which we do on demand.
if (request_template_.IsEmpty()) {
- Handle<ObjectTemplate> raw_template = MakeRequestTemplate();
+ Handle<ObjectTemplate> raw_template = MakeRequestTemplate(GetIsolate());
request_template_ =
Persistent<ObjectTemplate>::New(GetIsolate(), raw_template);
}
@@ -475,8 +478,9 @@ Handle<Value> JsHttpRequestProcessor::GetUserAgent(Local<String> name,
}
-Handle<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate() {
- HandleScope handle_scope;
+Handle<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate(
+ Isolate* isolate) {
+ HandleScope handle_scope(isolate);
Handle<ObjectTemplate> result = ObjectTemplate::New();
result->SetInternalFieldCount(1);
@@ -608,13 +612,14 @@ int main(int argc, char* argv[]) {
fprintf(stderr, "No script was specified.\n");
return 1;
}
- HandleScope scope;
+ Isolate* isolate = Isolate::GetCurrent();
+ HandleScope scope(isolate);
Handle<String> source = ReadFile(file);
if (source.IsEmpty()) {
fprintf(stderr, "Error reading '%s'.\n", file.c_str());
return 1;
}
- JsHttpRequestProcessor processor(source);
+ JsHttpRequestProcessor processor(isolate, source);
map<string, string> output;
if (!processor.Initialize(&options, &output)) {
fprintf(stderr, "Error initializing processor.\n");
Oops, something went wrong.

0 comments on commit 82809d0

Please sign in to comment.