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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 v8::Handle<Value> HandleGet(Local<String> key, | 91 static void HandleGet(Local<String> key, |
92 const AccessorInfo& info); | 92 const v8::PropertyCallbackInfo<v8::Value>& info); |
93 static v8::Handle<Value> HandleSet(Local<String> key, | 93 static void HandleSet(Local<String> key, |
94 Local<Value> value, | 94 Local<Value> value, |
95 const AccessorInfo& info); | 95 const v8::PropertyCallbackInfo<v8::Value>& info); |
96 static v8::Handle<Integer> HandleQuery(Local<String> key, | 96 static void HandleQuery(Local<String> key, |
97 const AccessorInfo& info); | 97 const v8::PropertyCallbackInfo<v8::Integer>& info); |
98 | 98 |
99 private: | 99 private: |
100 bool is_initialized_; | 100 bool is_initialized_; |
101 Persistent<Context> context_; | 101 Persistent<Context> context_; |
102 | 102 |
103 int get_count_; | 103 int get_count_; |
104 int set_count_; | 104 int set_count_; |
105 int query_count_; | 105 int query_count_; |
106 | 106 |
107 static DeclarationContext* GetInstance(const AccessorInfo& info); | 107 static DeclarationContext* GetInstance(Local<Value> data); |
108 }; | 108 }; |
109 | 109 |
110 | 110 |
111 DeclarationContext::DeclarationContext() | 111 DeclarationContext::DeclarationContext() |
112 : is_initialized_(false), get_count_(0), set_count_(0), query_count_(0) { | 112 : is_initialized_(false), get_count_(0), set_count_(0), query_count_(0) { |
113 // Do nothing. | 113 // Do nothing. |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 void DeclarationContext::InitializeIfNeeded() { | 117 void DeclarationContext::InitializeIfNeeded() { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 CHECK(expectations == EXPECT_EXCEPTION); | 166 CHECK(expectations == EXPECT_EXCEPTION); |
167 CHECK(catcher.HasCaught()); | 167 CHECK(catcher.HasCaught()); |
168 if (!value.IsEmpty()) { | 168 if (!value.IsEmpty()) { |
169 CHECK_EQ(value, catcher.Exception()); | 169 CHECK_EQ(value, catcher.Exception()); |
170 } | 170 } |
171 } | 171 } |
172 HEAP->CollectAllAvailableGarbage(); // Clean slate for the next test. | 172 HEAP->CollectAllAvailableGarbage(); // Clean slate for the next test. |
173 } | 173 } |
174 | 174 |
175 | 175 |
176 v8::Handle<Value> DeclarationContext::HandleGet(Local<String> key, | 176 void DeclarationContext::HandleGet( |
177 const AccessorInfo& info) { | 177 Local<String> key, |
178 DeclarationContext* context = GetInstance(info); | 178 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 179 DeclarationContext* context = GetInstance(info.Data()); |
179 context->get_count_++; | 180 context->get_count_++; |
180 return context->Get(key); | 181 info.GetReturnValue().Set(context->Get(key)); |
181 } | 182 } |
182 | 183 |
183 | 184 |
184 v8::Handle<Value> DeclarationContext::HandleSet(Local<String> key, | 185 void DeclarationContext::HandleSet( |
185 Local<Value> value, | 186 Local<String> key, |
186 const AccessorInfo& info) { | 187 Local<Value> value, |
187 DeclarationContext* context = GetInstance(info); | 188 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 189 DeclarationContext* context = GetInstance(info.Data()); |
188 context->set_count_++; | 190 context->set_count_++; |
189 return context->Set(key, value); | 191 info.GetReturnValue().Set(context->Set(key, value)); |
190 } | 192 } |
191 | 193 |
192 | 194 |
193 v8::Handle<Integer> DeclarationContext::HandleQuery(Local<String> key, | 195 void DeclarationContext::HandleQuery( |
194 const AccessorInfo& info) { | 196 Local<String> key, |
195 DeclarationContext* context = GetInstance(info); | 197 const v8::PropertyCallbackInfo<v8::Integer>& info) { |
| 198 DeclarationContext* context = GetInstance(info.Data()); |
196 context->query_count_++; | 199 context->query_count_++; |
197 return context->Query(key); | 200 info.GetReturnValue().Set(context->Query(key)); |
198 } | 201 } |
199 | 202 |
200 | 203 |
201 DeclarationContext* DeclarationContext::GetInstance(const AccessorInfo& info) { | 204 DeclarationContext* DeclarationContext::GetInstance(Local<Value> data) { |
202 void* value = External::Cast(*info.Data())->Value(); | 205 void* value = Local<External>::Cast(data)->Value(); |
203 return static_cast<DeclarationContext*>(value); | 206 return static_cast<DeclarationContext*>(value); |
204 } | 207 } |
205 | 208 |
206 | 209 |
207 v8::Handle<Value> DeclarationContext::Get(Local<String> key) { | 210 v8::Handle<Value> DeclarationContext::Get(Local<String> key) { |
208 return v8::Handle<Value>(); | 211 return v8::Handle<Value>(); |
209 } | 212 } |
210 | 213 |
211 | 214 |
212 v8::Handle<Value> DeclarationContext::Set(Local<String> key, | 215 v8::Handle<Value> DeclarationContext::Set(Local<String> key, |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 SimpleContext context; | 846 SimpleContext context; |
844 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); | 847 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); |
845 // TODO(rossberg): All tests should actually be errors in Harmony, | 848 // TODO(rossberg): All tests should actually be errors in Harmony, |
846 // but we currently do not detect the cases where the first declaration | 849 // but we currently do not detect the cases where the first declaration |
847 // is not lexical. | 850 // is not lexical. |
848 context.Check(seconds[j], | 851 context.Check(seconds[j], |
849 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); | 852 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); |
850 } | 853 } |
851 } | 854 } |
852 } | 855 } |
OLD | NEW |