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

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: 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(
568 v8::String::NewFromUtf8(GetIsolate(),
569 "Invalid invocation: this is not an object!"));
570 return;
not at google - send to devlin 2014/12/08 22:29:11 Good catch, I think this is the right behaviour, t
robwu 2014/12/08 22:39:24 Done.
571 }
568 v8::Local<v8::Object> obj = args[0].As<v8::Object>(); 572 v8::Local<v8::Object> obj = args[0].As<v8::Object>();
569 v8::Local<v8::String> privates_key = 573 v8::Local<v8::String> privates_key =
570 v8::String::NewFromUtf8(GetIsolate(), "privates"); 574 v8::String::NewFromUtf8(GetIsolate(), "privates");
571 v8::Local<v8::Value> privates = obj->GetHiddenValue(privates_key); 575 v8::Local<v8::Value> privates = obj->GetHiddenValue(privates_key);
572 if (privates.IsEmpty()) { 576 if (privates.IsEmpty()) {
573 privates = v8::Object::New(args.GetIsolate()); 577 privates = v8::Object::New(args.GetIsolate());
574 if (privates.IsEmpty()) { 578 if (privates.IsEmpty()) {
575 GetIsolate()->ThrowException( 579 GetIsolate()->ThrowException(
576 v8::String::NewFromUtf8(GetIsolate(), "Failed to create privates")); 580 v8::String::NewFromUtf8(GetIsolate(), "Failed to create privates"));
577 return; 581 return;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 v8::Handle<v8::Value> value) { 674 v8::Handle<v8::Value> value) {
671 if (!is_valid()) 675 if (!is_valid())
672 return; 676 return;
673 v8::HandleScope handle_scope(GetIsolate()); 677 v8::HandleScope handle_scope(GetIsolate());
674 v8::Handle<v8::Promise::Resolver> resolver_local( 678 v8::Handle<v8::Promise::Resolver> resolver_local(
675 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver)); 679 v8::Local<v8::Promise::Resolver>::New(GetIsolate(), *resolver));
676 resolver_local->Resolve(value); 680 resolver_local->Resolve(value);
677 } 681 }
678 682
679 } // namespace extensions 683 } // 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