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

Unified Diff: net/proxy/proxy_resolver_v8.cc

Issue 235001: Backport r27035.... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 3 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 | « net/data/proxy_resolver_v8_unittest/ends_with_comment.js ('k') | net/proxy/proxy_resolver_v8_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/proxy_resolver_v8.cc
===================================================================
--- net/proxy/proxy_resolver_v8.cc (revision 27049)
+++ net/proxy/proxy_resolver_v8.cc (working copy)
@@ -25,6 +25,8 @@
// Pseudo-name for the PAC script.
const char kPacResourceName[] = "proxy-pac-script.js";
+// Pseudo-name for the PAC utility script.
+const char kPacUtilityResourceName[] = "proxy-pac-utility-script.js";
// Convert a V8 String to a std::string.
std::string V8StringToStdString(v8::Handle<v8::String> s) {
@@ -254,21 +256,18 @@
v8::Context::Scope ctx(v8_context_);
- v8::TryCatch try_catch;
+ // Add the PAC utility functions to the environment.
+ // (This script should never fail, as it is a string literal!)
+ int rv = RunScript(PROXY_RESOLVER_SCRIPT, kPacUtilityResourceName);
+ if (rv != OK) {
+ NOTREACHED();
+ return;
+ }
- // Compile the script, including the PAC library functions.
- std::string text_raw = pac_data + PROXY_RESOLVER_SCRIPT;
- v8::Local<v8::String> text = StdStringToV8String(text_raw);
- v8::ScriptOrigin origin = v8::ScriptOrigin(
- v8::String::New(kPacResourceName));
- v8::Local<v8::Script> code = v8::Script::Compile(text, &origin);
-
- // Execute.
- if (!code.IsEmpty())
- code->Run();
-
- if (try_catch.HasCaught())
- HandleError(try_catch.Message());
+ // Add the user's PAC code to the environment.
+ rv = RunScript(pac_data, kPacResourceName);
+ if (rv != OK)
+ return;
}
// Handle an exception thrown by V8.
@@ -283,6 +282,29 @@
js_bindings_->OnError(line_number, error_message);
}
+ // Compiles and runs |script_utf8| in the current V8 context.
+ // Returns OK on success, otherwise an error code.
+ int RunScript(const std::string& script_utf8, const char* script_name) {
+ v8::TryCatch try_catch;
+
+ // Compile the script.
+ v8::Local<v8::String> text = StdStringToV8String(script_utf8);
+ v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New(script_name));
+ v8::Local<v8::Script> code = v8::Script::Compile(text, &origin);
+
+ // Execute.
+ if (!code.IsEmpty())
+ code->Run();
+
+ // Check for errors.
+ if (try_catch.HasCaught()) {
+ HandleError(try_catch.Message());
+ return ERR_PAC_SCRIPT_FAILED;
+ }
+
+ return OK;
+ }
+
// V8 callback for when "alert()" is invoked by the PAC script.
static v8::Handle<v8::Value> AlertCallback(const v8::Arguments& args) {
Context* context =
« no previous file with comments | « net/data/proxy_resolver_v8_unittest/ends_with_comment.js ('k') | net/proxy/proxy_resolver_v8_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698