Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Unified Diff: samples/process.cc

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Feedback. Rebased Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/lineprocessor.cc ('k') | samples/shell.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/process.cc
diff --git a/samples/process.cc b/samples/process.cc
index c3d17738bf14348e9b10f97eb9baa23e8d752cd5..4dcc09a56b775c101ade9fced34b176e4b4eb7b1 100644
--- a/samples/process.cc
+++ b/samples/process.cc
@@ -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,12 +138,12 @@ 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();
}
@@ -149,7 +151,7 @@ static Handle<Value> LogCallback(const Arguments& args) {
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");
« no previous file with comments | « samples/lineprocessor.cc ('k') | samples/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698