Lines Matching refs:v8
25 #include "v8/include/v8.h"
85 // External string wrapper so V8 can access the UTF16 string wrapped by
88 : public v8::String::ExternalStringResource {
107 // External string wrapper so V8 can access a string literal.
108 class V8ExternalASCIILiteral : public v8::String::ExternalAsciiStringResource {
131 // When creating a v8::String from a C++ string we have two choices: create
138 // Converts a V8 String to a UTF8 std::string.
139 std::string V8StringToUTF8(v8::Handle<v8::String> s) {
145 // Converts a V8 String to a UTF16 string16.
146 string16 V8StringToUTF16(v8::Handle<v8::String> s) {
155 // Converts an ASCII std::string to a V8 string.
156 v8::Local<v8::String> ASCIIStringToV8String(const std::string& s) {
158 return v8::String::New(s.data(), s.size());
162 // V8 string.
163 v8::Local<v8::String> ScriptDataToV8String(
166 return v8::String::New(
170 return v8::String::NewExternal(new V8ExternalStringFromScriptData(s));
173 // Converts an ASCII string literal to a V8 string.
174 v8::Local<v8::String> ASCIILiteralToV8String(const char* ascii) {
178 return v8::String::New(ascii, length);
179 return v8::String::NewExternal(new V8ExternalASCIILiteral(ascii, length));
182 // Stringizes a V8 object by calling its toString() method. Returns true
184 bool V8ObjectToUTF16String(v8::Handle<v8::Value> object,
189 v8::HandleScope scope;
190 v8::Local<v8::String> str_object = object->ToString();
199 bool GetHostnameArgument(const v8::Arguments& args, std::string* hostname) {
339 v8::Locker locked;
344 // Run the V8 garbage collector. We do this to be sure the
352 v8::Locker locked;
353 v8::HandleScope scope;
355 v8::Context::Scope function_scope(v8_context_);
357 v8::Local<v8::Value> function;
364 v8::Handle<v8::Value> argv[] = {
369 v8::TryCatch try_catch;
370 v8::Local<v8::Value> ret = v8::Function::Cast(*function)->Call(
403 v8::Locker locked;
404 v8::HandleScope scope;
406 v8_this_ = v8::Persistent<v8::External>::New(v8::External::New(this));
407 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
410 v8::Local<v8::FunctionTemplate> alert_template =
411 v8::FunctionTemplate::New(&AlertCallback, v8_this_);
414 v8::Local<v8::FunctionTemplate> my_ip_address_template =
415 v8::FunctionTemplate::New(&MyIpAddressCallback, v8_this_);
419 v8::Local<v8::FunctionTemplate> dns_resolve_template =
420 v8::FunctionTemplate::New(&DnsResolveCallback, v8_this_);
426 v8::Local<v8::FunctionTemplate> dns_resolve_ex_template =
427 v8::FunctionTemplate::New(&DnsResolveExCallback, v8_this_);
431 v8::Local<v8::FunctionTemplate> my_ip_address_ex_template =
432 v8::FunctionTemplate::New(&MyIpAddressExCallback, v8_this_);
436 v8::Local<v8::FunctionTemplate> sort_ip_address_list_template =
437 v8::FunctionTemplate::New(&SortIpAddressListCallback, v8_this_);
441 v8::Local<v8::FunctionTemplate> is_in_net_ex_template =
442 v8::FunctionTemplate::New(&IsInNetExCallback, v8_this_);
446 v8_context_ = v8::Context::New(NULL, global_template);
448 v8::Context::Scope ctx(v8_context_);
470 v8::Local<v8::Value> function;
482 v8::Locker locked;
483 // Repeatedly call the V8 idle notification until it returns true ("nothing
487 while (!v8::V8::IdleNotification())
492 bool GetFindProxyForURL(v8::Local<v8::Value>* function) {
498 // Handle an exception thrown by V8.
499 void HandleError(v8::Handle<v8::Message> message) {
510 // Compiles and runs |script| in the current V8 context.
512 int RunScript(v8::Handle<v8::String> script, const char* script_name) {
513 v8::TryCatch try_catch;
516 v8::ScriptOrigin origin =
517 v8::ScriptOrigin(ASCIILiteralToV8String(script_name));
518 v8::Local<v8::Script> code = v8::Script::Compile(script, &origin);
533 // V8 callback for when "alert()" is invoked by the PAC script.
534 static v8::Handle<v8::Value> AlertCallback(const v8::Arguments& args) {
536 static_cast<Context*>(v8::External::Cast(*args.Data())->Value());
545 return v8::Undefined(); // toString() threw an exception.
549 return v8::Undefined();
552 // V8 callback for when "myIpAddress()" is invoked by the PAC script.
553 static v8::Handle<v8::Value> MyIpAddressCallback(const v8::Arguments& args) {
555 static_cast<Context*>(v8::External::Cast(*args.Data())->Value());
561 v8::Unlocker unlocker;
573 // V8 callback for when "myIpAddressEx()" is invoked by the PAC script.
574 static v8::Handle<v8::Value> MyIpAddressExCallback(
575 const v8::Arguments& args) {
577 static_cast<Context*>(v8::External::Cast(*args.Data())->Value());
583 v8::Unlocker unlocker;
595 // V8 callback for when "dnsResolve()" is invoked by the PAC script.
596 static v8::Handle<v8::Value> DnsResolveCallback(const v8::Arguments& args) {
598 static_cast<Context*>(v8::External::Cast(*args.Data())->Value());
603 return v8::Null();
609 v8::Unlocker unlocker;
613 return success ? ASCIIStringToV8String(ip_address) : v8::Null();
616 // V8 callback for when "dnsResolveEx()" is invoked by the PAC script.
617 static v8::Handle<v8::Value> DnsResolveExCallback(const v8::Arguments& args) {
619 static_cast<Context*>(v8::External::Cast(*args.Data())->Value());
624 return v8::Undefined();
630 v8::Unlocker unlocker;
640 // V8 callback for when "sortIpAddressList()" is invoked by the PAC script.
641 static v8::Handle<v8::Value> SortIpAddressListCallback(
642 const v8::Arguments& args) {
645 return v8::Null();
649 return v8::Null();
653 return v8::False();
657 // V8 callback for when "isInNetEx()" is invoked by the PAC script.
658 static v8::Handle<v8::Value> IsInNetExCallback(const v8::Arguments& args) {
662 return v8::Null();
666 return v8::False();
669 return v8::False();
670 return IsInNetEx(ip_address, ip_prefix) ? v8::True() : v8::False();
674 v8::Persistent<v8::External> v8_this_;
675 v8::Persistent<v8::Context> v8_context_;
693 // If the V8 instance has not been initialized (either because
711 // Otherwise call into V8.