OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/module_system.h" | 5 #include "extensions/renderer/module_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 LoadModule(module_name); | 544 LoadModule(module_name); |
545 } | 545 } |
546 | 546 |
547 v8::Handle<v8::String> ModuleSystem::WrapSource(v8::Handle<v8::String> source) { | 547 v8::Handle<v8::String> ModuleSystem::WrapSource(v8::Handle<v8::String> source) { |
548 v8::EscapableHandleScope handle_scope(GetIsolate()); | 548 v8::EscapableHandleScope handle_scope(GetIsolate()); |
549 // Keep in order with the arguments in RequireForJsInner. | 549 // Keep in order with the arguments in RequireForJsInner. |
550 v8::Handle<v8::String> left = v8::String::NewFromUtf8( | 550 v8::Handle<v8::String> left = v8::String::NewFromUtf8( |
551 GetIsolate(), | 551 GetIsolate(), |
552 "(function(define, require, requireNative, requireAsync, exports, " | 552 "(function(define, require, requireNative, requireAsync, exports, " |
553 "console, privates," | 553 "console, privates," |
554 "$Array, $Function, $JSON, $Object, $RegExp, $String) {" | 554 "$Array, $Function, $JSON, $Object, $RegExp, $String, $Error) {" |
555 "'use strict';"); | 555 "'use strict';"); |
556 v8::Handle<v8::String> right = v8::String::NewFromUtf8(GetIsolate(), "\n})"); | 556 v8::Handle<v8::String> right = v8::String::NewFromUtf8(GetIsolate(), "\n})"); |
557 return handle_scope.Escape(v8::Local<v8::String>( | 557 return handle_scope.Escape(v8::Local<v8::String>( |
558 v8::String::Concat(left, v8::String::Concat(source, right)))); | 558 v8::String::Concat(left, v8::String::Concat(source, right)))); |
559 } | 559 } |
560 | 560 |
561 void ModuleSystem::Private(const v8::FunctionCallbackInfo<v8::Value>& args) { | 561 void ModuleSystem::Private(const v8::FunctionCallbackInfo<v8::Value>& args) { |
562 CHECK_EQ(1, args.Length()); | 562 CHECK_EQ(1, args.Length()); |
563 CHECK(args[0]->IsObject()); | 563 CHECK(args[0]->IsObject()); |
564 v8::Local<v8::Object> obj = args[0].As<v8::Object>(); | 564 v8::Local<v8::Object> obj = args[0].As<v8::Object>(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 console::AsV8Object(), | 617 console::AsV8Object(), |
618 natives->Get(v8::String::NewFromUtf8( | 618 natives->Get(v8::String::NewFromUtf8( |
619 GetIsolate(), "privates", v8::String::kInternalizedString)), | 619 GetIsolate(), "privates", v8::String::kInternalizedString)), |
620 // Each safe builtin. Keep in order with the arguments in WrapSource. | 620 // Each safe builtin. Keep in order with the arguments in WrapSource. |
621 context_->safe_builtins()->GetArray(), | 621 context_->safe_builtins()->GetArray(), |
622 context_->safe_builtins()->GetFunction(), | 622 context_->safe_builtins()->GetFunction(), |
623 context_->safe_builtins()->GetJSON(), | 623 context_->safe_builtins()->GetJSON(), |
624 context_->safe_builtins()->GetObjekt(), | 624 context_->safe_builtins()->GetObjekt(), |
625 context_->safe_builtins()->GetRegExp(), | 625 context_->safe_builtins()->GetRegExp(), |
626 context_->safe_builtins()->GetString(), | 626 context_->safe_builtins()->GetString(), |
| 627 context_->safe_builtins()->GetError(), |
627 }; | 628 }; |
628 { | 629 { |
629 v8::TryCatch try_catch; | 630 v8::TryCatch try_catch; |
630 try_catch.SetCaptureMessage(true); | 631 try_catch.SetCaptureMessage(true); |
631 context_->CallFunction(func, arraysize(args), args); | 632 context_->CallFunction(func, arraysize(args), args); |
632 if (try_catch.HasCaught()) { | 633 if (try_catch.HasCaught()) { |
633 HandleException(try_catch); | 634 HandleException(try_catch); |
634 return v8::Undefined(GetIsolate()); | 635 return v8::Undefined(GetIsolate()); |
635 } | 636 } |
636 } | 637 } |
(...skipping 23 matching lines...) Expand all Loading... |
660 v8::Handle<v8::Value> value) { | 661 v8::Handle<v8::Value> value) { |
661 if (!is_valid()) | 662 if (!is_valid()) |
662 return; | 663 return; |
663 v8::HandleScope handle_scope(GetIsolate()); | 664 v8::HandleScope handle_scope(GetIsolate()); |
664 v8::Handle<v8::Promise::Resolver> resolver_local( | 665 v8::Handle<v8::Promise::Resolver> resolver_local( |
665 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); | 666 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); |
666 resolver_local->Resolve(value); | 667 resolver_local->Resolve(value); |
667 } | 668 } |
668 | 669 |
669 } // namespace extensions | 670 } // namespace extensions |
OLD | NEW |