diff options
author | piman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-29 04:41:12 +0000 |
---|---|---|
committer | piman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-29 04:41:12 +0000 |
commit | 0ff7beb2415356524598953d8c21173cb06cf2bd (patch) | |
tree | 04cd4a20ee7d04caaa451900e73ff38add383c1e /o3d | |
parent | 9fba98e3fe4e8c45615befd358bddd308adfa58e (diff) | |
download | chromium_src-0ff7beb2415356524598953d8c21173cb06cf2bd.zip chromium_src-0ff7beb2415356524598953d8c21173cb06cf2bd.tar.gz chromium_src-0ff7beb2415356524598953d8c21173cb06cf2bd.tar.bz2 |
fix v8 issues by not adding explicit () in eval unless it's necessary.
Review URL: http://codereview.chromium.org/557055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37499 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/plugin/cross/np_v8_bridge.cc | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/o3d/plugin/cross/np_v8_bridge.cc b/o3d/plugin/cross/np_v8_bridge.cc index 5fa93e4..b0732d4 100644 --- a/o3d/plugin/cross/np_v8_bridge.cc +++ b/o3d/plugin/cross/np_v8_bridge.cc @@ -706,25 +706,30 @@ bool NPV8Bridge::Evaluate(const NPVariant* np_args, int numArgs, if (v8_code.IsEmpty() || !v8_code->IsString()) return false; - // Newer versions of v8 doesn't like eval('function () { ... }') but wants - // instead eval('(function () { ... })'), so add a pair of ( ) around the - // given string. - Local<v8::String> v8_code_string = v8_code->ToString(); - int length = v8_code_string->Utf8Length(); - // Note: this string is not 0-terminated. - scoped_array<char> paren_string(new char[length + 2]); - v8_code_string->WriteUtf8(paren_string.get() + 1, length); - paren_string[0] = '('; - paren_string[length + 1] = ')'; - v8_code_string = v8::String::New(paren_string.get(), length + 2); - - TryCatch tryCatch; + Local<v8::String> v8_code_string = v8_code->ToString(); Local<Script> v8_script = v8::Script::Compile(v8_code_string); + if (tryCatch.HasCaught()) { - ReportV8Exception(tryCatch); - return false; + // Newer version of v8 doesn't like eval('function () { ... }') but wants + // instead eval('(function () { ... })'). Old js code may still try to pass + // that in, so add a pair of ( ) around the given string, and try again. + tryCatch.Reset(); + int length = v8_code_string->Utf8Length(); + // Note: this string is not 0-terminated. + scoped_array<char> paren_string(new char[length + 2]); + v8_code_string->WriteUtf8(paren_string.get() + 1, length); + paren_string[0] = '('; + paren_string[length + 1] = ')'; + v8_code_string = v8::String::New(paren_string.get(), length + 2); + + v8_script = v8::Script::Compile(v8_code_string); + + if (tryCatch.HasCaught()) { + ReportV8Exception(tryCatch); + return false; + } } if (v8_script.IsEmpty()) return false; |