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

Side by Side Diff: test/cctest/test-api.cc

Issue 7229007: Add possibility to configure 'prototype' property via FunctionTemplate (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 9 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
« src/api.cc ('K') | « src/objects-inl.h ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 6824 matching lines...) Expand 10 before | Expand all | Expand 10 after
6835 Local<Value> proto1 = o1->GetPrototype(); 6835 Local<Value> proto1 = o1->GetPrototype();
6836 CHECK(proto1->IsObject()); 6836 CHECK(proto1->IsObject());
6837 CHECK_EQ(proto1.As<v8::Object>(), o2); 6837 CHECK_EQ(proto1.As<v8::Object>(), o2);
6838 6838
6839 Local<Value> proto2 = o2->GetPrototype(); 6839 Local<Value> proto2 = o2->GetPrototype();
6840 CHECK(proto2->IsObject()); 6840 CHECK(proto2->IsObject());
6841 CHECK_EQ(proto2.As<v8::Object>(), o3); 6841 CHECK_EQ(proto2.As<v8::Object>(), o3);
6842 } 6842 }
6843 6843
6844 6844
6845 THREADED_TEST(SetPrototypeProperties) {
6846 ASSERT(i::FunctionTemplateInfo::kPrototypePropertiesOffset ==
Mads Ager (chromium) 2011/06/22 12:13:46 This assert seems like an internal detail that we
Jakob Kummerow 2011/06/22 12:36:59 Done. Removed.
6847 15*i::kPointerSize + i::HeapObject::kHeaderSize);
6848 v8::HandleScope handle_scope;
6849 LocalContext context;
6850
6851 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
6852 t1->SetPrototypeProperties(v8::DontDelete);
6853 context->Global()->Set(v8_str("func1"), t1->GetFunction());
6854 CHECK(CompileRun(
6855 "(function() {"
6856 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
6857 " return (descriptor['writable'] == true) &&"
6858 " (descriptor['enumerable'] == true) &&"
6859 " (descriptor['configurable'] == false);"
6860 "})()")->BooleanValue());
6861
6862 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
6863 t2->SetPrototypeProperties(v8::DontEnum);
6864 context->Global()->Set(v8_str("func2"), t2->GetFunction());
6865 CHECK(CompileRun(
6866 "(function() {"
6867 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
6868 " return (descriptor['writable'] == true) &&"
6869 " (descriptor['enumerable'] == false) &&"
6870 " (descriptor['configurable'] == true);"
6871 "})()")->BooleanValue());
6872
6873 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New();
6874 t3->SetPrototypeProperties(v8::ReadOnly);
6875 context->Global()->Set(v8_str("func3"), t3->GetFunction());
6876 CHECK(CompileRun(
6877 "(function() {"
6878 " descriptor = Object.getOwnPropertyDescriptor(func3, 'prototype');"
6879 " return (descriptor['writable'] == false) &&"
6880 " (descriptor['enumerable'] == true) &&"
6881 " (descriptor['configurable'] == true);"
6882 "})()")->BooleanValue());
6883 }
Mads Ager (chromium) 2011/06/22 12:13:46 Let's add a test for the combination of all three
Jakob Kummerow 2011/06/22 12:36:59 Done.
6884
6885
6845 THREADED_TEST(SetPrototypeThrows) { 6886 THREADED_TEST(SetPrototypeThrows) {
6846 v8::HandleScope handle_scope; 6887 v8::HandleScope handle_scope;
6847 LocalContext context; 6888 LocalContext context;
6848 6889
6849 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 6890 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
6850 6891
6851 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); 6892 Local<v8::Object> o0 = t->GetFunction()->NewInstance();
6852 Local<v8::Object> o1 = t->GetFunction()->NewInstance(); 6893 Local<v8::Object> o1 = t->GetFunction()->NewInstance();
6853 6894
6854 CHECK(o0->SetPrototype(o1)); 6895 CHECK(o0->SetPrototype(o1));
(...skipping 7704 matching lines...) Expand 10 before | Expand all | Expand 10 after
14559 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1"))); 14600 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1")));
14560 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); 14601 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly);
14561 obj->Set(v8_num(2), v8_str("foobar")); 14602 obj->Set(v8_num(2), v8_str("foobar"));
14562 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2))); 14603 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2)));
14563 14604
14564 // Test non-smi case. 14605 // Test non-smi case.
14565 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); 14606 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly);
14566 obj->Set(v8_str("2000000000"), v8_str("foobar")); 14607 obj->Set(v8_str("2000000000"), v8_str("foobar"));
14567 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000"))); 14608 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000")));
14568 } 14609 }
OLDNEW
« src/api.cc ('K') | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698