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

Side by Side Diff: net/proxy/proxy_resolver_v8.cc

Issue 23861002: Remove calls to HandleScope default ctor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/v8_value_converter_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/proxy/proxy_resolver_v8.h" 5 #include "net/proxy/proxy_resolver_v8.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdio> 8 #include <cstdio>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 DCHECK(IsStringASCII(ascii)); 177 DCHECK(IsStringASCII(ascii));
178 size_t length = strlen(ascii); 178 size_t length = strlen(ascii);
179 if (length <= kMaxStringBytesForCopy) 179 if (length <= kMaxStringBytesForCopy)
180 return v8::String::New(ascii, length); 180 return v8::String::New(ascii, length);
181 return v8::String::NewExternal(new V8ExternalASCIILiteral(ascii, length)); 181 return v8::String::NewExternal(new V8ExternalASCIILiteral(ascii, length));
182 } 182 }
183 183
184 // Stringizes a V8 object by calling its toString() method. Returns true 184 // Stringizes a V8 object by calling its toString() method. Returns true
185 // on success. This may fail if the toString() throws an exception. 185 // on success. This may fail if the toString() throws an exception.
186 bool V8ObjectToUTF16String(v8::Handle<v8::Value> object, 186 bool V8ObjectToUTF16String(v8::Handle<v8::Value> object,
187 base::string16* utf16_result) { 187 base::string16* utf16_result,
188 v8::Isolate* isolate) {
188 if (object.IsEmpty()) 189 if (object.IsEmpty())
189 return false; 190 return false;
190 191
191 v8::HandleScope scope; 192 v8::HandleScope scope(isolate);
192 v8::Local<v8::String> str_object = object->ToString(); 193 v8::Local<v8::String> str_object = object->ToString();
193 if (str_object.IsEmpty()) 194 if (str_object.IsEmpty())
194 return false; 195 return false;
195 *utf16_result = V8StringToUTF16(str_object); 196 *utf16_result = V8StringToUTF16(str_object);
196 return true; 197 return true;
197 } 198 }
198 199
199 // Extracts an hostname argument from |args|. On success returns true 200 // Extracts an hostname argument from |args|. On success returns true
200 // and fills |*hostname| with the result. 201 // and fills |*hostname| with the result.
201 bool GetHostnameArgument(const v8::FunctionCallbackInfo<v8::Value>& args, 202 bool GetHostnameArgument(const v8::FunctionCallbackInfo<v8::Value>& args,
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 return (*function)->IsFunction(); 501 return (*function)->IsFunction();
501 } 502 }
502 503
503 // Handle an exception thrown by V8. 504 // Handle an exception thrown by V8.
504 void HandleError(v8::Handle<v8::Message> message) { 505 void HandleError(v8::Handle<v8::Message> message) {
505 base::string16 error_message; 506 base::string16 error_message;
506 int line_number = -1; 507 int line_number = -1;
507 508
508 if (!message.IsEmpty()) { 509 if (!message.IsEmpty()) {
509 line_number = message->GetLineNumber(); 510 line_number = message->GetLineNumber();
510 V8ObjectToUTF16String(message->Get(), &error_message); 511 V8ObjectToUTF16String(message->Get(), &error_message, isolate_);
511 } 512 }
512 513
513 js_bindings()->OnError(line_number, error_message); 514 js_bindings()->OnError(line_number, error_message);
514 } 515 }
515 516
516 // Compiles and runs |script| in the current V8 context. 517 // Compiles and runs |script| in the current V8 context.
517 // Returns OK on success, otherwise an error code. 518 // Returns OK on success, otherwise an error code.
518 int RunScript(v8::Handle<v8::String> script, const char* script_name) { 519 int RunScript(v8::Handle<v8::String> script, const char* script_name) {
519 v8::TryCatch try_catch; 520 v8::TryCatch try_catch;
520 521
(...skipping 19 matching lines...) Expand all
540 static void AlertCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { 541 static void AlertCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
541 Context* context = 542 Context* context =
542 static_cast<Context*>(v8::External::Cast(*args.Data())->Value()); 543 static_cast<Context*>(v8::External::Cast(*args.Data())->Value());
543 544
544 // Like firefox we assume "undefined" if no argument was specified, and 545 // Like firefox we assume "undefined" if no argument was specified, and
545 // disregard any arguments beyond the first. 546 // disregard any arguments beyond the first.
546 base::string16 message; 547 base::string16 message;
547 if (args.Length() == 0) { 548 if (args.Length() == 0) {
548 message = ASCIIToUTF16("undefined"); 549 message = ASCIIToUTF16("undefined");
549 } else { 550 } else {
550 if (!V8ObjectToUTF16String(args[0], &message)) 551 if (!V8ObjectToUTF16String(args[0], &message, args.GetIsolate()))
551 return; // toString() threw an exception. 552 return; // toString() threw an exception.
552 } 553 }
553 554
554 context->js_bindings()->Alert(message); 555 context->js_bindings()->Alert(message);
555 } 556 }
556 557
557 // V8 callback for when "myIpAddress()" is invoked by the PAC script. 558 // V8 callback for when "myIpAddress()" is invoked by the PAC script.
558 static void MyIpAddressCallback( 559 static void MyIpAddressCallback(
559 const v8::FunctionCallbackInfo<v8::Value>& args) { 560 const v8::FunctionCallbackInfo<v8::Value>& args) {
560 DnsResolveCallbackHelper(args, JSBindings::MY_IP_ADDRESS); 561 DnsResolveCallbackHelper(args, JSBindings::MY_IP_ADDRESS);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 if (!g_default_isolate_) 800 if (!g_default_isolate_)
800 return 0; 801 return 0;
801 802
802 v8::Locker locked(g_default_isolate_); 803 v8::Locker locked(g_default_isolate_);
803 v8::HeapStatistics heap_statistics; 804 v8::HeapStatistics heap_statistics;
804 g_default_isolate_->GetHeapStatistics(&heap_statistics); 805 g_default_isolate_->GetHeapStatistics(&heap_statistics);
805 return heap_statistics.used_heap_size(); 806 return heap_statistics.used_heap_size();
806 } 807 }
807 808
808 } // namespace net 809 } // namespace net
OLDNEW
« no previous file with comments | « content/renderer/v8_value_converter_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698