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

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

Issue 209853002: add setaccessorproperty to object (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: gcc fix Created 6 years, 9 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/api.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 21944 matching lines...) Expand 10 before | Expand all | Expand 10 after
21955 CHECK(data == info.Data()); 21955 CHECK(data == info.Data());
21956 CHECK(receiver == info.This()); 21956 CHECK(receiver == info.This());
21957 if (info.Length() == 1) { 21957 if (info.Length() == 1) {
21958 CHECK_EQ(v8_num(1), info[0]); 21958 CHECK_EQ(v8_num(1), info[0]);
21959 } 21959 }
21960 CHECK(holder == info.Holder()); 21960 CHECK(holder == info.Holder());
21961 count++; 21961 count++;
21962 info.GetReturnValue().Set(v8_str("returned")); 21962 info.GetReturnValue().Set(v8_str("returned"));
21963 } 21963 }
21964 21964
21965 // TODO(dcarney): move this to v8.h
21966 static void SetAccessorProperty(Local<Object> object,
21967 Local<String> name,
21968 Local<Function> getter,
21969 Local<Function> setter = Local<Function>()) {
21970 i::Isolate* isolate = CcTest::i_isolate();
21971 v8::AccessControl settings = v8::DEFAULT;
21972 v8::PropertyAttribute attribute = v8::None;
21973 i::Handle<i::Object> getter_i = v8::Utils::OpenHandle(*getter);
21974 i::Handle<i::Object> setter_i = v8::Utils::OpenHandle(*setter, true);
21975 if (setter_i.is_null()) setter_i = isolate->factory()->null_value();
21976 i::JSObject::DefineAccessor(v8::Utils::OpenHandle(*object),
21977 v8::Utils::OpenHandle(*name),
21978 getter_i,
21979 setter_i,
21980 static_cast<PropertyAttributes>(attribute),
21981 settings);
21982 }
21983
21984 public: 21965 public:
21985 enum SignatureType { 21966 enum SignatureType {
21986 kNoSignature, 21967 kNoSignature,
21987 kSignatureOnReceiver, 21968 kSignatureOnReceiver,
21988 kSignatureOnPrototype 21969 kSignatureOnPrototype
21989 }; 21970 };
21990 21971
21991 void RunAll() { 21972 void RunAll() {
21992 SignatureType signature_types[] = 21973 SignatureType signature_types[] =
21993 {kNoSignature, kSignatureOnReceiver, kSignatureOnPrototype}; 21974 {kNoSignature, kSignatureOnReceiver, kSignatureOnPrototype};
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
22042 Local<FunctionTemplate> function_template = FunctionTemplate::New( 22023 Local<FunctionTemplate> function_template = FunctionTemplate::New(
22043 isolate, OptimizationCallback, data, signature); 22024 isolate, OptimizationCallback, data, signature);
22044 Local<Function> function = function_template->GetFunction(); 22025 Local<Function> function = function_template->GetFunction();
22045 Local<Object> global_holder = inner_global; 22026 Local<Object> global_holder = inner_global;
22046 Local<Object> function_holder = function_receiver; 22027 Local<Object> function_holder = function_receiver;
22047 if (signature_type == kSignatureOnPrototype) { 22028 if (signature_type == kSignatureOnPrototype) {
22048 function_holder = Local<Object>::Cast(function_holder->GetPrototype()); 22029 function_holder = Local<Object>::Cast(function_holder->GetPrototype());
22049 global_holder = Local<Object>::Cast(global_holder->GetPrototype()); 22030 global_holder = Local<Object>::Cast(global_holder->GetPrototype());
22050 } 22031 }
22051 global_holder->Set(v8_str("g_f"), function); 22032 global_holder->Set(v8_str("g_f"), function);
22052 SetAccessorProperty(global_holder, v8_str("g_acc"), function, function); 22033 global_holder->SetAccessorProperty(v8_str("g_acc"), function, function);
22053 function_holder->Set(v8_str("f"), function); 22034 function_holder->Set(v8_str("f"), function);
22054 SetAccessorProperty(function_holder, v8_str("acc"), function, function); 22035 function_holder->SetAccessorProperty(v8_str("acc"), function, function);
22055 // Initialize expected values. 22036 // Initialize expected values.
22056 callee = function; 22037 callee = function;
22057 count = 0; 22038 count = 0;
22058 if (global) { 22039 if (global) {
22059 receiver = context->Global(); 22040 receiver = context->Global();
22060 holder = inner_global; 22041 holder = inner_global;
22061 } else { 22042 } else {
22062 holder = function_receiver; 22043 holder = function_receiver;
22063 // If not using a signature, add something else to the prototype chain 22044 // If not using a signature, add something else to the prototype chain
22064 // to test the case that holder != receiver 22045 // to test the case that holder != receiver
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
22336 "f.call(friend);"); 22317 "f.call(friend);");
22337 CHECK_EQ(2, named_access_count); 22318 CHECK_EQ(2, named_access_count);
22338 22319
22339 // Test access using Object.setPrototypeOf reflective method. 22320 // Test access using Object.setPrototypeOf reflective method.
22340 named_access_count = 0; 22321 named_access_count = 0;
22341 CompileRun("Object.setPrototypeOf(friend, {});"); 22322 CompileRun("Object.setPrototypeOf(friend, {});");
22342 CHECK_EQ(1, named_access_count); 22323 CHECK_EQ(1, named_access_count);
22343 CompileRun("Object.getPrototypeOf(friend);"); 22324 CompileRun("Object.getPrototypeOf(friend);");
22344 CHECK_EQ(2, named_access_count); 22325 CHECK_EQ(2, named_access_count);
22345 } 22326 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698