OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 void Check(const char* source, | 63 void Check(const char* source, |
64 int get, int set, int has, | 64 int get, int set, int has, |
65 Expectations expectations, | 65 Expectations expectations, |
66 v8::Handle<Value> value = Local<Value>()); | 66 v8::Handle<Value> value = Local<Value>()); |
67 | 67 |
68 int get_count() const { return get_count_; } | 68 int get_count() const { return get_count_; } |
69 int set_count() const { return set_count_; } | 69 int set_count() const { return set_count_; } |
70 int query_count() const { return query_count_; } | 70 int query_count() const { return query_count_; } |
71 | 71 |
72 protected: | 72 protected: |
73 virtual v8::Handle<Value> Get(Local<String> key); | 73 virtual v8::Handle<Value> Get(Local<Name> key); |
74 virtual v8::Handle<Value> Set(Local<String> key, Local<Value> value); | 74 virtual v8::Handle<Value> Set(Local<Name> key, Local<Value> value); |
75 virtual v8::Handle<Integer> Query(Local<String> key); | 75 virtual v8::Handle<Integer> Query(Local<Name> key); |
76 | 76 |
77 void InitializeIfNeeded(); | 77 void InitializeIfNeeded(); |
78 | 78 |
79 // Perform optional initialization steps on the context after it has | 79 // Perform optional initialization steps on the context after it has |
80 // been created. Defaults to none but may be overwritten. | 80 // been created. Defaults to none but may be overwritten. |
81 virtual void PostInitializeContext(Handle<Context> context) {} | 81 virtual void PostInitializeContext(Handle<Context> context) {} |
82 | 82 |
83 // Get the holder for the interceptor. Default to the instance template | 83 // Get the holder for the interceptor. Default to the instance template |
84 // but may be overwritten. | 84 // but may be overwritten. |
85 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 85 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
86 return function->InstanceTemplate(); | 86 return function->InstanceTemplate(); |
87 } | 87 } |
88 | 88 |
89 // The handlers are called as static functions that forward | 89 // The handlers are called as static functions that forward |
90 // to the instance specific virtual methods. | 90 // to the instance specific virtual methods. |
91 static void HandleGet(Local<String> key, | 91 static void HandleGet(Local<Name> key, |
92 const v8::PropertyCallbackInfo<v8::Value>& info); | 92 const v8::PropertyCallbackInfo<v8::Value>& info); |
93 static void HandleSet(Local<String> key, | 93 static void HandleSet(Local<Name> key, |
94 Local<Value> value, | 94 Local<Value> value, |
95 const v8::PropertyCallbackInfo<v8::Value>& info); | 95 const v8::PropertyCallbackInfo<v8::Value>& info); |
96 static void HandleQuery(Local<String> key, | 96 static void HandleQuery(Local<Name> key, |
97 const v8::PropertyCallbackInfo<v8::Integer>& info); | 97 const v8::PropertyCallbackInfo<v8::Integer>& info); |
98 | 98 |
99 v8::Isolate* isolate() const { return CcTest::isolate(); } | 99 v8::Isolate* isolate() const { return CcTest::isolate(); } |
100 | 100 |
101 private: | 101 private: |
102 bool is_initialized_; | 102 bool is_initialized_; |
103 Persistent<Context> context_; | 103 Persistent<Context> context_; |
104 | 104 |
105 int get_count_; | 105 int get_count_; |
106 int set_count_; | 106 int set_count_; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 if (!value.IsEmpty()) { | 171 if (!value.IsEmpty()) { |
172 CHECK_EQ(value, catcher.Exception()); | 172 CHECK_EQ(value, catcher.Exception()); |
173 } | 173 } |
174 } | 174 } |
175 // Clean slate for the next test. | 175 // Clean slate for the next test. |
176 CcTest::heap()->CollectAllAvailableGarbage(); | 176 CcTest::heap()->CollectAllAvailableGarbage(); |
177 } | 177 } |
178 | 178 |
179 | 179 |
180 void DeclarationContext::HandleGet( | 180 void DeclarationContext::HandleGet( |
181 Local<String> key, | 181 Local<Name> key, |
182 const v8::PropertyCallbackInfo<v8::Value>& info) { | 182 const v8::PropertyCallbackInfo<v8::Value>& info) { |
183 DeclarationContext* context = GetInstance(info.Data()); | 183 DeclarationContext* context = GetInstance(info.Data()); |
184 context->get_count_++; | 184 context->get_count_++; |
185 info.GetReturnValue().Set(context->Get(key)); | 185 info.GetReturnValue().Set(context->Get(key)); |
186 } | 186 } |
187 | 187 |
188 | 188 |
189 void DeclarationContext::HandleSet( | 189 void DeclarationContext::HandleSet( |
190 Local<String> key, | 190 Local<Name> key, |
191 Local<Value> value, | 191 Local<Value> value, |
192 const v8::PropertyCallbackInfo<v8::Value>& info) { | 192 const v8::PropertyCallbackInfo<v8::Value>& info) { |
193 DeclarationContext* context = GetInstance(info.Data()); | 193 DeclarationContext* context = GetInstance(info.Data()); |
194 context->set_count_++; | 194 context->set_count_++; |
195 info.GetReturnValue().Set(context->Set(key, value)); | 195 info.GetReturnValue().Set(context->Set(key, value)); |
196 } | 196 } |
197 | 197 |
198 | 198 |
199 void DeclarationContext::HandleQuery( | 199 void DeclarationContext::HandleQuery( |
200 Local<String> key, | 200 Local<Name> key, |
201 const v8::PropertyCallbackInfo<v8::Integer>& info) { | 201 const v8::PropertyCallbackInfo<v8::Integer>& info) { |
202 DeclarationContext* context = GetInstance(info.Data()); | 202 DeclarationContext* context = GetInstance(info.Data()); |
203 context->query_count_++; | 203 context->query_count_++; |
204 info.GetReturnValue().Set(context->Query(key)); | 204 info.GetReturnValue().Set(context->Query(key)); |
205 } | 205 } |
206 | 206 |
207 | 207 |
208 DeclarationContext* DeclarationContext::GetInstance(Local<Value> data) { | 208 DeclarationContext* DeclarationContext::GetInstance(Local<Value> data) { |
209 void* value = Local<External>::Cast(data)->Value(); | 209 void* value = Local<External>::Cast(data)->Value(); |
210 return static_cast<DeclarationContext*>(value); | 210 return static_cast<DeclarationContext*>(value); |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 v8::Handle<Value> DeclarationContext::Get(Local<String> key) { | 214 v8::Handle<Value> DeclarationContext::Get(Local<Name> key) { |
215 return v8::Handle<Value>(); | 215 return v8::Handle<Value>(); |
216 } | 216 } |
217 | 217 |
218 | 218 |
219 v8::Handle<Value> DeclarationContext::Set(Local<String> key, | 219 v8::Handle<Value> DeclarationContext::Set(Local<Name> key, |
220 Local<Value> value) { | 220 Local<Value> value) { |
221 return v8::Handle<Value>(); | 221 return v8::Handle<Value>(); |
222 } | 222 } |
223 | 223 |
224 | 224 |
225 v8::Handle<Integer> DeclarationContext::Query(Local<String> key) { | 225 v8::Handle<Integer> DeclarationContext::Query(Local<Name> key) { |
226 return v8::Handle<Integer>(); | 226 return v8::Handle<Integer>(); |
227 } | 227 } |
228 | 228 |
229 | 229 |
230 // Test global declaration of a property the interceptor doesn't know | 230 // Test global declaration of a property the interceptor doesn't know |
231 // about and doesn't handle. | 231 // about and doesn't handle. |
232 TEST(Unknown) { | 232 TEST(Unknown) { |
233 HandleScope scope(CcTest::isolate()); | 233 HandleScope scope(CcTest::isolate()); |
234 v8::V8::Initialize(); | 234 v8::V8::Initialize(); |
235 | 235 |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 Number::New(CcTest::isolate(), 1)); | 706 Number::New(CcTest::isolate(), 1)); |
707 // TODO(rossberg): All tests should actually be errors in Harmony, | 707 // TODO(rossberg): All tests should actually be errors in Harmony, |
708 // but we currently do not detect the cases where the first declaration | 708 // but we currently do not detect the cases where the first declaration |
709 // is not lexical. | 709 // is not lexical. |
710 context.Check(seconds[j], | 710 context.Check(seconds[j], |
711 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, | 711 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, |
712 Number::New(CcTest::isolate(), 2)); | 712 Number::New(CcTest::isolate(), 2)); |
713 } | 713 } |
714 } | 714 } |
715 } | 715 } |
OLD | NEW |