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

Unified Diff: net/proxy/proxy_resolver_v8.cc

Issue 223016: Fix a bug where if a PAC script ended with a comment and no newline, it would... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remove unused TryCatch 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 26790)
+++ net/proxy/proxy_resolver_v8.cc (working copy)
@@ -20,6 +20,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) {
@@ -130,24 +132,19 @@
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 rv;
+ }
- // Compile the script, including the PAC library functions.
- std::string text_raw_utf8 = pac_data_utf8 + PROXY_RESOLVER_SCRIPT;
- v8::Local<v8::String> text = StdStringToV8String(text_raw_utf8);
- v8::ScriptOrigin origin = v8::ScriptOrigin(
- v8::String::New(kPacResourceName));
- v8::Local<v8::Script> code = v8::Script::Compile(text, &origin);
+ // Add the user's PAC code to the environment.
+ rv = RunScript(pac_data_utf8, kPacResourceName);
+ if (rv != OK)
+ return rv;
- // Execute.
- if (!code.IsEmpty())
- code->Run();
-
- if (try_catch.HasCaught()) {
- HandleError(try_catch.Message());
- return ERR_PAC_SCRIPT_FAILED;
- }
-
// At a minimum, the FindProxyForURL() function must be defined for this
// to be a legitimiate PAC script.
v8::Local<v8::Value> function;
@@ -179,6 +176,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