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

Side by Side Diff: extensions/renderer/module_system.cc

Issue 783333002: Throw JavaScript error instead of CHECK when this in privates is invalid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add elaborate error message for undefined Created 6 years 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
« no previous file with comments | « no previous file | 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 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
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(v8::Exception::TypeError(
568 args[0]->IsUndefined() ?
not at google - send to devlin 2014/12/08 22:48:11 I think the ternary here looks pretty weird. I had
robwu 2014/12/08 22:51:27 Would it help if I put the ? and : at the start of
robwu 2014/12/08 23:08:38 Done (I put ? and : in front of the line and ran g
569 "Method called without a valid receiver (this)."
570 "Did you forget to call .bind()?" :
571 "Invalid invocation: this is not an object!"));
572 return;
573 }
568 v8::Local<v8::Object> obj = args[0].As<v8::Object>(); 574 v8::Local<v8::Object> obj = args[0].As<v8::Object>();
569 v8::Local<v8::String> privates_key = 575 v8::Local<v8::String> privates_key =
570 v8::String::NewFromUtf8(GetIsolate(), "privates"); 576 v8::String::NewFromUtf8(GetIsolate(), "privates");
571 v8::Local<v8::Value> privates = obj->GetHiddenValue(privates_key); 577 v8::Local<v8::Value> privates = obj->GetHiddenValue(privates_key);
572 if (privates.IsEmpty()) { 578 if (privates.IsEmpty()) {
573 privates = v8::Object::New(args.GetIsolate()); 579 privates = v8::Object::New(args.GetIsolate());
574 if (privates.IsEmpty()) { 580 if (privates.IsEmpty()) {
575 GetIsolate()->ThrowException( 581 GetIsolate()->ThrowException(
576 v8::String::NewFromUtf8(GetIsolate(), "Failed to create privates")); 582 v8::String::NewFromUtf8(GetIsolate(), "Failed to create privates"));
577 return; 583 return;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 v8::Handle<v8::Value> value) { 676 v8::Handle<v8::Value> value) {
671 if (!is_valid()) 677 if (!is_valid())
672 return; 678 return;
673 v8::HandleScope handle_scope(GetIsolate()); 679 v8::HandleScope handle_scope(GetIsolate());
674 v8::Handle<v8::Promise::Resolver> resolver_local( 680 v8::Handle<v8::Promise::Resolver> resolver_local(
675 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); 681 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver));
676 resolver_local->Resolve(value); 682 resolver_local->Resolve(value);
677 } 683 }
678 684
679 } // namespace extensions 685 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698