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

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

Issue 7324027: Fix: FunctionTemplate::SetPrototypeAttributes broke prototype object (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: address comments Created 9 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.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 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 6951 matching lines...) Expand 10 before | Expand all | Expand 10 after
6962 Local<Value> proto1 = o1->GetPrototype(); 6962 Local<Value> proto1 = o1->GetPrototype();
6963 CHECK(proto1->IsObject()); 6963 CHECK(proto1->IsObject());
6964 CHECK_EQ(proto1.As<v8::Object>(), o2); 6964 CHECK_EQ(proto1.As<v8::Object>(), o2);
6965 6965
6966 Local<Value> proto2 = o2->GetPrototype(); 6966 Local<Value> proto2 = o2->GetPrototype();
6967 CHECK(proto2->IsObject()); 6967 CHECK(proto2->IsObject());
6968 CHECK_EQ(proto2.As<v8::Object>(), o3); 6968 CHECK_EQ(proto2.As<v8::Object>(), o3);
6969 } 6969 }
6970 6970
6971 6971
6972 THREADED_TEST(SetPrototypeProperties) { 6972 THREADED_TEST(FunctionReadOnlyPrototype) {
6973 v8::HandleScope handle_scope; 6973 v8::HandleScope handle_scope;
6974 LocalContext context; 6974 LocalContext context;
6975 6975
6976 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 6976 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
6977 t1->SetPrototypeAttributes(v8::DontDelete); 6977 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42));
6978 t1->ReadOnlyPrototype();
6978 context->Global()->Set(v8_str("func1"), t1->GetFunction()); 6979 context->Global()->Set(v8_str("func1"), t1->GetFunction());
6980 // Configured value of ReadOnly flag.
6979 CHECK(CompileRun( 6981 CHECK(CompileRun(
6980 "(function() {" 6982 "(function() {"
6981 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" 6983 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
6982 " return (descriptor['writable'] == true) &&" 6984 " return (descriptor['writable'] == false);"
6983 " (descriptor['enumerable'] == true) &&"
6984 " (descriptor['configurable'] == false);"
6985 "})()")->BooleanValue()); 6985 "})()")->BooleanValue());
6986 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value());
6987 CHECK_EQ(42,
6988 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value());
6986 6989
6987 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 6990 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
6988 t2->SetPrototypeAttributes(v8::DontEnum); 6991 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42));
6989 context->Global()->Set(v8_str("func2"), t2->GetFunction()); 6992 context->Global()->Set(v8_str("func2"), t2->GetFunction());
6993 // Default value of ReadOnly flag.
6990 CHECK(CompileRun( 6994 CHECK(CompileRun(
6991 "(function() {" 6995 "(function() {"
6992 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" 6996 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
6993 " return (descriptor['writable'] == true) &&" 6997 " return (descriptor['writable'] == true);"
6994 " (descriptor['enumerable'] == false) &&"
6995 " (descriptor['configurable'] == true);"
6996 "})()")->BooleanValue()); 6998 "})()")->BooleanValue());
6997 6999 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value());
6998 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New();
6999 t3->SetPrototypeAttributes(v8::ReadOnly);
7000 context->Global()->Set(v8_str("func3"), t3->GetFunction());
7001 CHECK(CompileRun(
7002 "(function() {"
7003 " descriptor = Object.getOwnPropertyDescriptor(func3, 'prototype');"
7004 " return (descriptor['writable'] == false) &&"
7005 " (descriptor['enumerable'] == true) &&"
7006 " (descriptor['configurable'] == true);"
7007 "})()")->BooleanValue());
7008
7009 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New();
7010 t4->SetPrototypeAttributes(v8::ReadOnly | v8::DontEnum | v8::DontDelete);
7011 context->Global()->Set(v8_str("func4"), t4->GetFunction());
7012 CHECK(CompileRun(
7013 "(function() {"
7014 " descriptor = Object.getOwnPropertyDescriptor(func4, 'prototype');"
7015 " return (descriptor['writable'] == false) &&"
7016 " (descriptor['enumerable'] == false) &&"
7017 " (descriptor['configurable'] == false);"
7018 "})()")->BooleanValue());
7019 } 7000 }
7020 7001
7021 7002
7022 THREADED_TEST(SetPrototypeThrows) { 7003 THREADED_TEST(SetPrototypeThrows) {
7023 v8::HandleScope handle_scope; 7004 v8::HandleScope handle_scope;
7024 LocalContext context; 7005 LocalContext context;
7025 7006
7026 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 7007 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
7027 7008
7028 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); 7009 Local<v8::Object> o0 = t->GetFunction()->NewInstance();
(...skipping 7734 matching lines...) Expand 10 before | Expand all | Expand 10 after
14763 } 14744 }
14764 14745
14765 i::Isolate::Current()->heap()->CollectAllGarbage(true); 14746 i::Isolate::Current()->heap()->CollectAllGarbage(true);
14766 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); 14747 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache();
14767 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { 14748 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) {
14768 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); 14749 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache);
14769 CHECK_GT(elements, map_cache->NumberOfElements()); 14750 CHECK_GT(elements, map_cache->NumberOfElements());
14770 } 14751 }
14771 } 14752 }
14772 } 14753 }
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698