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

Side by Side Diff: chrome/renderer/extensions/safe_builtins.cc

Issue 17451011: Make the externally connectable browser test clobber all of the builtins, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hopefully fix tests Created 7 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/renderer/extensions/safe_builtins.h" 5 #include "chrome/renderer/extensions/safe_builtins.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/renderer/extensions/chrome_v8_context.h" 10 #include "chrome/renderer/extensions/chrome_v8_context.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 " });\n" 52 " });\n"
53 "}\n" 53 "}\n"
54 "\n" 54 "\n"
55 "function getSafeBuiltin(builtin) {\n" 55 "function getSafeBuiltin(builtin) {\n"
56 " var safe = {};\n" 56 " var safe = {};\n"
57 " makeCallable(builtin, safe, true);\n" 57 " makeCallable(builtin, safe, true);\n"
58 " makeCallable(builtin.prototype, safe, false);\n" 58 " makeCallable(builtin.prototype, safe, false);\n"
59 " return safe;\n" 59 " return safe;\n"
60 "}\n" 60 "}\n"
61 "\n" 61 "\n"
62 "[Array, Function, Object].forEach(function(builtin) {\n" 62 "[Array, Function, Object, RegExp, String].forEach(function(builtin) {\n"
63 " Save(builtin.name, getSafeBuiltin(builtin));\n" 63 " Save(builtin.name, getSafeBuiltin(builtin));\n"
64 "});\n" 64 "});\n"
65 "}());\n"; 65 "}());\n";
66 66
67 v8::Local<v8::String> MakeKey(const char* name) { 67 v8::Local<v8::String> MakeKey(const char* name) {
68 return v8::String::New( 68 return v8::String::New(
69 base::StringPrintf("%s::%s", kClassName, name).c_str()); 69 base::StringPrintf("%s::%s", kClassName, name).c_str());
70 } 70 }
71 71
72 void SaveImpl(const char* name, 72 void SaveImpl(const char* name,
(...skipping 21 matching lines...) Expand all
94 return v8::FunctionTemplate::New(Apply); 94 return v8::FunctionTemplate::New(Apply);
95 if (name->Equals(v8::String::New("Save"))) 95 if (name->Equals(v8::String::New("Save")))
96 return v8::FunctionTemplate::New(Save); 96 return v8::FunctionTemplate::New(Save);
97 NOTREACHED() << *v8::String::AsciiValue(name); 97 NOTREACHED() << *v8::String::AsciiValue(name);
98 return v8::Handle<v8::FunctionTemplate>(); 98 return v8::Handle<v8::FunctionTemplate>();
99 } 99 }
100 100
101 static void Apply(const v8::FunctionCallbackInfo<v8::Value>& info) { 101 static void Apply(const v8::FunctionCallbackInfo<v8::Value>& info) {
102 CHECK(info.Length() == 5 && 102 CHECK(info.Length() == 5 &&
103 info[0]->IsFunction() && // function 103 info[0]->IsFunction() && // function
104 // info[1]->Object() // recv (will throw error not check) 104 // info[1]->Object() // recv (will throw error not check)
Jeffrey Yasskin 2013/06/20 23:33:04 Object() isn't correct anymore, so update this com
not at google - send to devlin 2013/06/21 00:01:44 Done.
105 info[2]->IsObject() && // args 105 info[2]->IsObject() && // args
106 info[3]->IsInt32() && // first_arg_index 106 info[3]->IsInt32() && // first_arg_index
107 info[4]->IsInt32()); // args_length 107 info[4]->IsInt32()); // args_length
108 if (!info[1]->IsObject()) { 108 v8::Local<v8::Function> function = info[0].As<v8::Function>();
109 v8::Local<v8::Object> recv;
110 if (info[1]->IsObject()) {
111 recv = info[1]->ToObject();
112 } else if (info[1]->IsString()) {
113 recv = v8::StringObject::New(info[1]->ToString())->ToObject();
Jeffrey Yasskin 2013/06/20 23:33:04 Why are you creating a new string here instead of
not at google - send to devlin 2013/06/21 00:01:44 No new string is being created, ToString() is just
114 } else {
109 v8::ThrowException(v8::Exception::TypeError(v8::String::New( 115 v8::ThrowException(v8::Exception::TypeError(v8::String::New(
110 "The first argument is the receiver and must be an object"))); 116 "The first argument is the receiver and must be an object")));
111 return; 117 return;
112 } 118 }
113 v8::Local<v8::Function> function = info[0].As<v8::Function>();
114 v8::Local<v8::Object> recv = info[1]->ToObject();
115 v8::Local<v8::Object> args = info[2]->ToObject(); 119 v8::Local<v8::Object> args = info[2]->ToObject();
116 int first_arg_index = static_cast<int>(info[3]->ToInt32()->Value()); 120 int first_arg_index = static_cast<int>(info[3]->ToInt32()->Value());
117 int args_length = static_cast<int>(info[4]->ToInt32()->Value()); 121 int args_length = static_cast<int>(info[4]->ToInt32()->Value());
118 122
119 int argc = args_length - first_arg_index; 123 int argc = args_length - first_arg_index;
120 scoped_ptr<v8::Local<v8::Value>[]> argv(new v8::Local<v8::Value>[argc]); 124 scoped_ptr<v8::Local<v8::Value>[]> argv(new v8::Local<v8::Value>[argc]);
121 for (int i = 0; i < argc; ++i) { 125 for (int i = 0; i < argc; ++i) {
122 CHECK(args->Has(i + first_arg_index)); 126 CHECK(args->Has(i + first_arg_index));
123 argv[i] = args->Get(i + first_arg_index); 127 argv[i] = args->Get(i + first_arg_index);
124 } 128 }
(...skipping 29 matching lines...) Expand all
154 } 158 }
155 159
156 v8::Local<v8::Object> SafeBuiltins::GetFunction() const { 160 v8::Local<v8::Object> SafeBuiltins::GetFunction() const {
157 return Load("Function", context_->v8_context()); 161 return Load("Function", context_->v8_context());
158 } 162 }
159 163
160 v8::Local<v8::Object> SafeBuiltins::GetObjekt() const { 164 v8::Local<v8::Object> SafeBuiltins::GetObjekt() const {
161 return Load("Object", context_->v8_context()); 165 return Load("Object", context_->v8_context());
162 } 166 }
163 167
168 v8::Local<v8::Object> SafeBuiltins::GetRegExp() const {
169 return Load("RegExp", context_->v8_context());
170 }
171
172 v8::Local<v8::Object> SafeBuiltins::GetString() const {
173 return Load("String", context_->v8_context());
174 }
175
164 } // namespace extensions 176 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698