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

Side by Side Diff: chrome/test/base/v8_unit_test.cc

Issue 2126763002: Remove the prototype from all V8 functions that aren't constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 4 years, 5 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
« no previous file with comments | « no previous file | extensions/renderer/console.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/test/base/v8_unit_test.h" 5 #include "chrome/test/base/v8_unit_test.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 AddLibrary(g_test_data_directory.AppendASCII("test_api.js")); 163 AddLibrary(g_test_data_directory.AppendASCII("test_api.js"));
164 } 164 }
165 165
166 void V8UnitTest::SetUp() { 166 void V8UnitTest::SetUp() {
167 v8::Isolate* isolate = blink::mainThreadIsolate(); 167 v8::Isolate* isolate = blink::mainThreadIsolate();
168 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); 168 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
169 v8::Local<v8::String> log_string = v8::String::NewFromUtf8(isolate, "log"); 169 v8::Local<v8::String> log_string = v8::String::NewFromUtf8(isolate, "log");
170 v8::Local<v8::FunctionTemplate> log_function = 170 v8::Local<v8::FunctionTemplate> log_function =
171 v8::FunctionTemplate::New(isolate, &V8UnitTest::Log); 171 v8::FunctionTemplate::New(isolate, &V8UnitTest::Log);
172 log_function->RemovePrototype();
172 global->Set(log_string, log_function); 173 global->Set(log_string, log_function);
173 174
174 // Set up chrome object for chrome.send(). 175 // Set up chrome object for chrome.send().
175 v8::Local<v8::ObjectTemplate> chrome = v8::ObjectTemplate::New(isolate); 176 v8::Local<v8::ObjectTemplate> chrome = v8::ObjectTemplate::New(isolate);
176 global->Set(v8::String::NewFromUtf8(isolate, "chrome"), chrome); 177 global->Set(v8::String::NewFromUtf8(isolate, "chrome"), chrome);
177 chrome->Set(v8::String::NewFromUtf8(isolate, "send"), 178 v8::Local<v8::FunctionTemplate> send_function =
178 v8::FunctionTemplate::New(isolate, &V8UnitTest::ChromeSend)); 179 v8::FunctionTemplate::New(isolate, &V8UnitTest::ChromeSend);
180 send_function->RemovePrototype();
181 chrome->Set(v8::String::NewFromUtf8(isolate, "send"), send_function);
179 182
180 // Set up console object for console.log(), etc. 183 // Set up console object for console.log(), etc.
181 v8::Local<v8::ObjectTemplate> console = v8::ObjectTemplate::New(isolate); 184 v8::Local<v8::ObjectTemplate> console = v8::ObjectTemplate::New(isolate);
182 global->Set(v8::String::NewFromUtf8(isolate, "console"), console); 185 global->Set(v8::String::NewFromUtf8(isolate, "console"), console);
183 console->Set(log_string, log_function); 186 console->Set(log_string, log_function);
184 console->Set(v8::String::NewFromUtf8(isolate, "info"), log_function); 187 console->Set(v8::String::NewFromUtf8(isolate, "info"), log_function);
185 console->Set(v8::String::NewFromUtf8(isolate, "warn"), log_function); 188 console->Set(v8::String::NewFromUtf8(isolate, "warn"), log_function);
186 console->Set(v8::String::NewFromUtf8(isolate, "error"), 189 v8::Local<v8::FunctionTemplate> error_function =
187 v8::FunctionTemplate::New(isolate, &V8UnitTest::Error)); 190 v8::FunctionTemplate::New(isolate, &V8UnitTest::Error);
191 error_function->RemovePrototype();
192 console->Set(v8::String::NewFromUtf8(isolate, "error"), error_function);
188 193
189 context_.Reset(isolate, v8::Context::New(isolate, NULL, global)); 194 context_.Reset(isolate, v8::Context::New(isolate, NULL, global));
190 } 195 }
191 196
192 void V8UnitTest::SetGlobalStringVar(const std::string& var_name, 197 void V8UnitTest::SetGlobalStringVar(const std::string& var_name,
193 const std::string& value) { 198 const std::string& value) {
194 v8::Isolate* isolate = blink::mainThreadIsolate(); 199 v8::Isolate* isolate = blink::mainThreadIsolate();
195 v8::Local<v8::Context> context = 200 v8::Local<v8::Context> context =
196 v8::Local<v8::Context>::New(isolate, context_); 201 v8::Local<v8::Context>::New(isolate, context_);
197 v8::Context::Scope context_scope(context); 202 v8::Context::Scope context_scope(context);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 v8::Local<v8::Array> test_result(args[1].As<v8::Array>()); 311 v8::Local<v8::Array> test_result(args[1].As<v8::Array>());
307 EXPECT_EQ(2U, test_result->Length()); 312 EXPECT_EQ(2U, test_result->Length());
308 if (::testing::Test::HasNonfatalFailure()) 313 if (::testing::Test::HasNonfatalFailure())
309 return; 314 return;
310 g_test_result_ok = test_result->Get(0)->BooleanValue(); 315 g_test_result_ok = test_result->Get(0)->BooleanValue();
311 if (!g_test_result_ok) { 316 if (!g_test_result_ok) {
312 v8::String::Utf8Value message(test_result->Get(1)); 317 v8::String::Utf8Value message(test_result->Get(1));
313 LOG(ERROR) << *message; 318 LOG(ERROR) << *message;
314 } 319 }
315 } 320 }
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/console.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698