| 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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 "console, privates," | 556 "console, privates," |
| 557 "$Array, $Function, $JSON, $Object, $RegExp, $String, $Error) {" | 557 "$Array, $Function, $JSON, $Object, $RegExp, $String, $Error) {" |
| 558 "'use strict';"); | 558 "'use strict';"); |
| 559 v8::Handle<v8::String> right = v8::String::NewFromUtf8(GetIsolate(), "\n})"); | 559 v8::Handle<v8::String> right = v8::String::NewFromUtf8(GetIsolate(), "\n})"); |
| 560 return handle_scope.Escape(v8::Local<v8::String>( | 560 return handle_scope.Escape(v8::Local<v8::String>( |
| 561 v8::String::Concat(left, v8::String::Concat(source, right)))); | 561 v8::String::Concat(left, v8::String::Concat(source, right)))); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void ModuleSystem::Private(const v8::FunctionCallbackInfo<v8::Value>& args) { | 564 void ModuleSystem::Private(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 565 CHECK_EQ(1, args.Length()); | 565 CHECK_EQ(1, args.Length()); |
| 566 CHECK(args[0]->IsObject()); | 566 if (!args[0]->IsObject() || args[0]->IsNull()) { |
| 567 CHECK(!args[0]->IsNull()); | 567 GetIsolate()->ThrowException( |
| 568 v8::Exception::TypeError(v8::String::NewFromUtf8(GetIsolate(), |
| 569 args[0]->IsUndefined() |
| 570 ? "Method called without a valid receiver (this). " |
| 571 "Did you forget to call .bind()?" |
| 572 : "Invalid invocation: receiver is not an object!"))); |
| 573 return; |
| 574 } |
| 568 v8::Local<v8::Object> obj = args[0].As<v8::Object>(); | 575 v8::Local<v8::Object> obj = args[0].As<v8::Object>(); |
| 569 v8::Local<v8::String> privates_key = | 576 v8::Local<v8::String> privates_key = |
| 570 v8::String::NewFromUtf8(GetIsolate(), "privates"); | 577 v8::String::NewFromUtf8(GetIsolate(), "privates"); |
| 571 v8::Local<v8::Value> privates = obj->GetHiddenValue(privates_key); | 578 v8::Local<v8::Value> privates = obj->GetHiddenValue(privates_key); |
| 572 if (privates.IsEmpty()) { | 579 if (privates.IsEmpty()) { |
| 573 privates = v8::Object::New(args.GetIsolate()); | 580 privates = v8::Object::New(args.GetIsolate()); |
| 574 if (privates.IsEmpty()) { | 581 if (privates.IsEmpty()) { |
| 575 GetIsolate()->ThrowException( | 582 GetIsolate()->ThrowException( |
| 576 v8::String::NewFromUtf8(GetIsolate(), "Failed to create privates")); | 583 v8::String::NewFromUtf8(GetIsolate(), "Failed to create privates")); |
| 577 return; | 584 return; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 v8::Handle<v8::Value> value) { | 677 v8::Handle<v8::Value> value) { |
| 671 if (!is_valid()) | 678 if (!is_valid()) |
| 672 return; | 679 return; |
| 673 v8::HandleScope handle_scope(GetIsolate()); | 680 v8::HandleScope handle_scope(GetIsolate()); |
| 674 v8::Handle<v8::Promise::Resolver> resolver_local( | 681 v8::Handle<v8::Promise::Resolver> resolver_local( |
| 675 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); | 682 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); |
| 676 resolver_local->Resolve(value); | 683 resolver_local->Resolve(value); |
| 677 } | 684 } |
| 678 | 685 |
| 679 } // namespace extensions | 686 } // namespace extensions |
| OLD | NEW |