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

Side by Side Diff: content/renderer/v8_value_converter_impl_unittest.cc

Issue 10837066: Fixing crash in V8ValueConverter. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: No getters Created 8 years, 4 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 | « content/renderer/v8_value_converter_impl.cc ('k') | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <cmath> 5 #include <cmath>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "content/renderer/v8_value_converter_impl.h" 9 #include "content/renderer/v8_value_converter_impl.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "v8/include/v8.h" 11 #include "v8/include/v8.h"
12 12
13 namespace {
14
15 // A dumb getter for an object's named callback.
16 v8::Handle<v8::Value> NamedCallbackGetter(v8::Local<v8::String> name,
17 const v8::AccessorInfo& info) {
18 return v8::String::New("bar");
19 }
20
21 } // namespace
22
13 class V8ValueConverterImplTest : public testing::Test { 23 class V8ValueConverterImplTest : public testing::Test {
14 protected: 24 protected:
15 virtual void SetUp() { 25 virtual void SetUp() {
16 v8::HandleScope handle_scope; 26 v8::HandleScope handle_scope;
17 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); 27 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
18 context_ = v8::Context::New(NULL, global); 28 context_ = v8::Context::New(NULL, global);
19 } 29 }
20 30
21 virtual void TearDown() { 31 virtual void TearDown() {
22 context_.Dispose(); 32 context_.Dispose();
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 array->Set(0, v8::String::New("1")); 380 array->Set(0, v8::String::New("1"));
371 array->Set(1, array); 381 array->Set(1, array);
372 382
373 scoped_ptr<ListValue> list_result( 383 scoped_ptr<ListValue> list_result(
374 static_cast<ListValue*>(converter.FromV8Value(array, context_))); 384 static_cast<ListValue*>(converter.FromV8Value(array, context_)));
375 ASSERT_TRUE(list_result.get()); 385 ASSERT_TRUE(list_result.get());
376 EXPECT_EQ(2u, list_result->GetSize()); 386 EXPECT_EQ(2u, list_result->GetSize());
377 EXPECT_TRUE(IsNull(list_result.get(), 1)); 387 EXPECT_TRUE(IsNull(list_result.get(), 1));
378 } 388 }
379 389
390 // Do not try and convert any named callbacks including getters.
380 TEST_F(V8ValueConverterImplTest, ObjectGetters) { 391 TEST_F(V8ValueConverterImplTest, ObjectGetters) {
381 v8::Context::Scope context_scope(context_); 392 v8::Context::Scope context_scope(context_);
382 v8::HandleScope handle_scope; 393 v8::HandleScope handle_scope;
383 394
384 const char* source = "(function() {" 395 const char* source = "(function() {"
385 "var a = {};" 396 "var a = {};"
386 "a.__defineGetter__('foo', function() { return 'bar'; });" 397 "a.__defineGetter__('foo', function() { return 'bar'; });"
387 "return a;" 398 "return a;"
388 "})();"; 399 "})();";
389 400
390 v8::Handle<v8::Script> script(v8::Script::New(v8::String::New(source))); 401 v8::Handle<v8::Script> script(v8::Script::New(v8::String::New(source)));
391 v8::Handle<v8::Object> object = script->Run().As<v8::Object>(); 402 v8::Handle<v8::Object> object = script->Run().As<v8::Object>();
392 ASSERT_FALSE(object.IsEmpty()); 403 ASSERT_FALSE(object.IsEmpty());
393 404
394 V8ValueConverterImpl converter; 405 V8ValueConverterImpl converter;
395 scoped_ptr<DictionaryValue> result( 406 scoped_ptr<DictionaryValue> result(
396 static_cast<DictionaryValue*>(converter.FromV8Value(object, context_))); 407 static_cast<DictionaryValue*>(converter.FromV8Value(object, context_)));
397 ASSERT_TRUE(result.get()); 408 ASSERT_TRUE(result.get());
409 EXPECT_EQ(0u, result->size());
410 }
411
412 // Do not try and convert any named callbacks including getters.
413 TEST_F(V8ValueConverterImplTest, ObjectWithInternalFieldsGetters) {
414 v8::Context::Scope context_scope(context_);
415 v8::HandleScope handle_scope;
416
417 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
418 object_template->SetInternalFieldCount(1);
419 object_template->SetAccessor(v8::String::New("foo"), NamedCallbackGetter);
420 v8::Handle<v8::Object> object = object_template->NewInstance();
421 ASSERT_FALSE(object.IsEmpty());
422 object->Set(v8::String::New("a"), v8::String::New("b"));
423
424 V8ValueConverterImpl converter;
425 scoped_ptr<DictionaryValue> result(
426 static_cast<DictionaryValue*>(converter.FromV8Value(object, context_)));
427 ASSERT_TRUE(result.get());
398 EXPECT_EQ(1u, result->size()); 428 EXPECT_EQ(1u, result->size());
399 } 429 }
400 430
401 TEST_F(V8ValueConverterImplTest, ArrayGetters) { 431 TEST_F(V8ValueConverterImplTest, ArrayGetters) {
402 v8::Context::Scope context_scope(context_); 432 v8::Context::Scope context_scope(context_);
403 v8::HandleScope handle_scope; 433 v8::HandleScope handle_scope;
404 434
405 const char* source = "(function() {" 435 const char* source = "(function() {"
406 "var a = [0];" 436 "var a = [0];"
407 "a.__defineGetter__(1, function() { return 'bar'; });" 437 "a.__defineGetter__(1, function() { return 'bar'; });"
408 "return a;" 438 "return a;"
409 "})();"; 439 "})();";
410 440
411 v8::Handle<v8::Script> script(v8::Script::New(v8::String::New(source))); 441 v8::Handle<v8::Script> script(v8::Script::New(v8::String::New(source)));
412 v8::Handle<v8::Array> array = script->Run().As<v8::Array>(); 442 v8::Handle<v8::Array> array = script->Run().As<v8::Array>();
413 ASSERT_FALSE(array.IsEmpty()); 443 ASSERT_FALSE(array.IsEmpty());
414 444
415 V8ValueConverterImpl converter; 445 V8ValueConverterImpl converter;
416 scoped_ptr<ListValue> result( 446 scoped_ptr<ListValue> result(
417 static_cast<ListValue*>(converter.FromV8Value(array, context_))); 447 static_cast<ListValue*>(converter.FromV8Value(array, context_)));
418 ASSERT_TRUE(result.get()); 448 ASSERT_TRUE(result.get());
419 EXPECT_EQ(2u, result->GetSize()); 449 EXPECT_EQ(2u, result->GetSize());
420 } 450 }
OLDNEW
« no previous file with comments | « content/renderer/v8_value_converter_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698