| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 | 29 |
| 30 #define USE_NEW_QUERY_CALLBACKS |
| 31 |
| 30 #include "v8.h" | 32 #include "v8.h" |
| 31 | 33 |
| 32 #include "heap.h" | 34 #include "heap.h" |
| 33 #include "cctest.h" | 35 #include "cctest.h" |
| 34 | 36 |
| 35 using namespace v8; | 37 using namespace v8; |
| 36 | 38 |
| 37 | 39 |
| 38 enum Expectations { | 40 enum Expectations { |
| 39 EXPECT_RESULT, | 41 EXPECT_RESULT, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 56 } | 58 } |
| 57 } | 59 } |
| 58 | 60 |
| 59 void Check(const char* source, | 61 void Check(const char* source, |
| 60 int get, int set, int has, | 62 int get, int set, int has, |
| 61 Expectations expectations, | 63 Expectations expectations, |
| 62 v8::Handle<Value> value = Local<Value>()); | 64 v8::Handle<Value> value = Local<Value>()); |
| 63 | 65 |
| 64 int get_count() const { return get_count_; } | 66 int get_count() const { return get_count_; } |
| 65 int set_count() const { return set_count_; } | 67 int set_count() const { return set_count_; } |
| 66 int has_count() const { return has_count_; } | 68 int query_count() const { return query_count_; } |
| 67 | 69 |
| 68 protected: | 70 protected: |
| 69 virtual v8::Handle<Value> Get(Local<String> key); | 71 virtual v8::Handle<Value> Get(Local<String> key); |
| 70 virtual v8::Handle<Value> Set(Local<String> key, Local<Value> value); | 72 virtual v8::Handle<Value> Set(Local<String> key, Local<Value> value); |
| 71 virtual v8::Handle<Boolean> Has(Local<String> key); | 73 virtual v8::Handle<Integer> Query(Local<String> key); |
| 72 | 74 |
| 73 void InitializeIfNeeded(); | 75 void InitializeIfNeeded(); |
| 74 | 76 |
| 75 // Get the holder for the interceptor. Default to the instance template | 77 // Get the holder for the interceptor. Default to the instance template |
| 76 // but may be overwritten. | 78 // but may be overwritten. |
| 77 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 79 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
| 78 return function->InstanceTemplate(); | 80 return function->InstanceTemplate(); |
| 79 } | 81 } |
| 80 | 82 |
| 81 // The handlers are called as static functions that forward | 83 // The handlers are called as static functions that forward |
| 82 // to the instance specific virtual methods. | 84 // to the instance specific virtual methods. |
| 83 static v8::Handle<Value> HandleGet(Local<String> key, | 85 static v8::Handle<Value> HandleGet(Local<String> key, |
| 84 const AccessorInfo& info); | 86 const AccessorInfo& info); |
| 85 static v8::Handle<Value> HandleSet(Local<String> key, | 87 static v8::Handle<Value> HandleSet(Local<String> key, |
| 86 Local<Value> value, | 88 Local<Value> value, |
| 87 const AccessorInfo& info); | 89 const AccessorInfo& info); |
| 88 static v8::Handle<Boolean> HandleHas(Local<String> key, | 90 static v8::Handle<Integer> HandleQuery(Local<String> key, |
| 89 const AccessorInfo& info); | 91 const AccessorInfo& info); |
| 90 | 92 |
| 91 private: | 93 private: |
| 92 bool is_initialized_; | 94 bool is_initialized_; |
| 93 Persistent<Context> context_; | 95 Persistent<Context> context_; |
| 94 Local<String> property_; | 96 Local<String> property_; |
| 95 | 97 |
| 96 int get_count_; | 98 int get_count_; |
| 97 int set_count_; | 99 int set_count_; |
| 98 int has_count_; | 100 int query_count_; |
| 99 | 101 |
| 100 static DeclarationContext* GetInstance(const AccessorInfo& info); | 102 static DeclarationContext* GetInstance(const AccessorInfo& info); |
| 101 }; | 103 }; |
| 102 | 104 |
| 103 | 105 |
| 104 DeclarationContext::DeclarationContext() | 106 DeclarationContext::DeclarationContext() |
| 105 : is_initialized_(false), get_count_(0), set_count_(0), has_count_(0) { | 107 : is_initialized_(false), get_count_(0), set_count_(0), query_count_(0) { |
| 106 // Do nothing. | 108 // Do nothing. |
| 107 } | 109 } |
| 108 | 110 |
| 109 | 111 |
| 110 void DeclarationContext::InitializeIfNeeded() { | 112 void DeclarationContext::InitializeIfNeeded() { |
| 111 if (is_initialized_) return; | 113 if (is_initialized_) return; |
| 112 HandleScope scope; | 114 HandleScope scope; |
| 113 Local<FunctionTemplate> function = FunctionTemplate::New(); | 115 Local<FunctionTemplate> function = FunctionTemplate::New(); |
| 114 Local<Value> data = External::New(this); | 116 Local<Value> data = External::New(this); |
| 115 GetHolder(function)->SetNamedPropertyHandler(&HandleGet, | 117 GetHolder(function)->SetNamedPropertyHandler(&HandleGet, |
| 116 &HandleSet, | 118 &HandleSet, |
| 117 &HandleHas, | 119 &HandleQuery, |
| 118 0, 0, | 120 0, 0, |
| 119 data); | 121 data); |
| 120 context_ = Context::New(0, function->InstanceTemplate(), Local<Value>()); | 122 context_ = Context::New(0, function->InstanceTemplate(), Local<Value>()); |
| 121 context_->Enter(); | 123 context_->Enter(); |
| 122 is_initialized_ = true; | 124 is_initialized_ = true; |
| 123 } | 125 } |
| 124 | 126 |
| 125 | 127 |
| 126 void DeclarationContext::Check(const char* source, | 128 void DeclarationContext::Check(const char* source, |
| 127 int get, int set, int has, | 129 int get, int set, int query, |
| 128 Expectations expectations, | 130 Expectations expectations, |
| 129 v8::Handle<Value> value) { | 131 v8::Handle<Value> value) { |
| 130 InitializeIfNeeded(); | 132 InitializeIfNeeded(); |
| 131 // A retry after a GC may pollute the counts, so perform gc now | 133 // A retry after a GC may pollute the counts, so perform gc now |
| 132 // to avoid that. | 134 // to avoid that. |
| 133 v8::internal::Heap::CollectGarbage(0, v8::internal::NEW_SPACE); | 135 v8::internal::Heap::CollectGarbage(0, v8::internal::NEW_SPACE); |
| 134 HandleScope scope; | 136 HandleScope scope; |
| 135 TryCatch catcher; | 137 TryCatch catcher; |
| 136 catcher.SetVerbose(true); | 138 catcher.SetVerbose(true); |
| 137 Local<Value> result = Script::Compile(String::New(source))->Run(); | 139 Local<Value> result = Script::Compile(String::New(source))->Run(); |
| 138 CHECK_EQ(get, get_count()); | 140 CHECK_EQ(get, get_count()); |
| 139 CHECK_EQ(set, set_count()); | 141 CHECK_EQ(set, set_count()); |
| 140 CHECK_EQ(has, has_count()); | 142 CHECK_EQ(query, query_count()); |
| 141 if (expectations == EXPECT_RESULT) { | 143 if (expectations == EXPECT_RESULT) { |
| 142 CHECK(!catcher.HasCaught()); | 144 CHECK(!catcher.HasCaught()); |
| 143 if (!value.IsEmpty()) { | 145 if (!value.IsEmpty()) { |
| 144 CHECK_EQ(value, result); | 146 CHECK_EQ(value, result); |
| 145 } | 147 } |
| 146 } else { | 148 } else { |
| 147 CHECK(expectations == EXPECT_EXCEPTION); | 149 CHECK(expectations == EXPECT_EXCEPTION); |
| 148 CHECK(catcher.HasCaught()); | 150 CHECK(catcher.HasCaught()); |
| 149 if (!value.IsEmpty()) { | 151 if (!value.IsEmpty()) { |
| 150 CHECK_EQ(value, catcher.Exception()); | 152 CHECK_EQ(value, catcher.Exception()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 163 | 165 |
| 164 v8::Handle<Value> DeclarationContext::HandleSet(Local<String> key, | 166 v8::Handle<Value> DeclarationContext::HandleSet(Local<String> key, |
| 165 Local<Value> value, | 167 Local<Value> value, |
| 166 const AccessorInfo& info) { | 168 const AccessorInfo& info) { |
| 167 DeclarationContext* context = GetInstance(info); | 169 DeclarationContext* context = GetInstance(info); |
| 168 context->set_count_++; | 170 context->set_count_++; |
| 169 return context->Set(key, value); | 171 return context->Set(key, value); |
| 170 } | 172 } |
| 171 | 173 |
| 172 | 174 |
| 173 v8::Handle<Boolean> DeclarationContext::HandleHas(Local<String> key, | 175 v8::Handle<Integer> DeclarationContext::HandleQuery(Local<String> key, |
| 174 const AccessorInfo& info) { | 176 const AccessorInfo& info) { |
| 175 DeclarationContext* context = GetInstance(info); | 177 DeclarationContext* context = GetInstance(info); |
| 176 context->has_count_++; | 178 context->query_count_++; |
| 177 return context->Has(key); | 179 return context->Query(key); |
| 178 } | 180 } |
| 179 | 181 |
| 180 | 182 |
| 181 DeclarationContext* DeclarationContext::GetInstance(const AccessorInfo& info) { | 183 DeclarationContext* DeclarationContext::GetInstance(const AccessorInfo& info) { |
| 182 return static_cast<DeclarationContext*>(External::Unwrap(info.Data())); | 184 return static_cast<DeclarationContext*>(External::Unwrap(info.Data())); |
| 183 } | 185 } |
| 184 | 186 |
| 185 | 187 |
| 186 v8::Handle<Value> DeclarationContext::Get(Local<String> key) { | 188 v8::Handle<Value> DeclarationContext::Get(Local<String> key) { |
| 187 return v8::Handle<Value>(); | 189 return v8::Handle<Value>(); |
| 188 } | 190 } |
| 189 | 191 |
| 190 | 192 |
| 191 v8::Handle<Value> DeclarationContext::Set(Local<String> key, | 193 v8::Handle<Value> DeclarationContext::Set(Local<String> key, |
| 192 Local<Value> value) { | 194 Local<Value> value) { |
| 193 return v8::Handle<Value>(); | 195 return v8::Handle<Value>(); |
| 194 } | 196 } |
| 195 | 197 |
| 196 | 198 |
| 197 v8::Handle<Boolean> DeclarationContext::Has(Local<String> key) { | 199 v8::Handle<Integer> DeclarationContext::Query(Local<String> key) { |
| 198 return v8::Handle<Boolean>(); | 200 return v8::Handle<Integer>(); |
| 199 } | 201 } |
| 200 | 202 |
| 201 | 203 |
| 202 // Test global declaration of a property the interceptor doesn't know | 204 // Test global declaration of a property the interceptor doesn't know |
| 203 // about and doesn't handle. | 205 // about and doesn't handle. |
| 204 TEST(Unknown) { | 206 TEST(Unknown) { |
| 205 HandleScope scope; | 207 HandleScope scope; |
| 206 | 208 |
| 207 { DeclarationContext context; | 209 { DeclarationContext context; |
| 208 context.Check("var x; x", | 210 context.Check("var x; x", |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 2, // declaration + initialization | 244 2, // declaration + initialization |
| 243 2, // declaration + initialization | 245 2, // declaration + initialization |
| 244 EXPECT_RESULT, Undefined()); // SB 0 - BUG 1213579 | 246 EXPECT_RESULT, Undefined()); // SB 0 - BUG 1213579 |
| 245 } | 247 } |
| 246 } | 248 } |
| 247 | 249 |
| 248 | 250 |
| 249 | 251 |
| 250 class PresentPropertyContext: public DeclarationContext { | 252 class PresentPropertyContext: public DeclarationContext { |
| 251 protected: | 253 protected: |
| 252 virtual v8::Handle<Boolean> Has(Local<String> key) { | 254 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 253 return True(); | 255 return Integer::New(v8::None); |
| 254 } | 256 } |
| 255 }; | 257 }; |
| 256 | 258 |
| 257 | 259 |
| 258 | 260 |
| 259 TEST(Present) { | 261 TEST(Present) { |
| 260 HandleScope scope; | 262 HandleScope scope; |
| 261 | 263 |
| 262 { PresentPropertyContext context; | 264 { PresentPropertyContext context; |
| 263 context.Check("var x; x", | 265 context.Check("var x; x", |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 0, | 299 0, |
| 298 1, // (re-)declaration | 300 1, // (re-)declaration |
| 299 EXPECT_EXCEPTION); // x has already been declared! | 301 EXPECT_EXCEPTION); // x has already been declared! |
| 300 } | 302 } |
| 301 } | 303 } |
| 302 | 304 |
| 303 | 305 |
| 304 | 306 |
| 305 class AbsentPropertyContext: public DeclarationContext { | 307 class AbsentPropertyContext: public DeclarationContext { |
| 306 protected: | 308 protected: |
| 307 virtual v8::Handle<Boolean> Has(Local<String> key) { | 309 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 308 return False(); | 310 return v8::Handle<Integer>(); |
| 309 } | 311 } |
| 310 }; | 312 }; |
| 311 | 313 |
| 312 | 314 |
| 313 TEST(Absent) { | 315 TEST(Absent) { |
| 314 HandleScope scope; | 316 HandleScope scope; |
| 315 | 317 |
| 316 { AbsentPropertyContext context; | 318 { AbsentPropertyContext context; |
| 317 context.Check("var x; x", | 319 context.Check("var x; x", |
| 318 1, // access | 320 1, // access |
| 319 2, // declaration + initialization | 321 1, // declaration |
| 320 2, // declaration + initialization | 322 2, // declaration + initialization |
| 321 EXPECT_RESULT, Undefined()); | 323 EXPECT_RESULT, Undefined()); |
| 322 } | 324 } |
| 323 | 325 |
| 324 { AbsentPropertyContext context; | 326 { AbsentPropertyContext context; |
| 325 context.Check("var x = 0; x", | 327 context.Check("var x = 0; x", |
| 326 1, // access | 328 1, // access |
| 327 2, // declaration + initialization | 329 2, // declaration + initialization |
| 328 2, // declaration + initialization | 330 2, // declaration + initialization |
| 329 EXPECT_RESULT, Number::New(0)); | 331 EXPECT_RESULT, Number::New(0)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 public: | 370 public: |
| 369 enum State { | 371 enum State { |
| 370 DECLARE, | 372 DECLARE, |
| 371 INITIALIZE_IF_ASSIGN, | 373 INITIALIZE_IF_ASSIGN, |
| 372 UNKNOWN | 374 UNKNOWN |
| 373 }; | 375 }; |
| 374 | 376 |
| 375 AppearingPropertyContext() : state_(DECLARE) { } | 377 AppearingPropertyContext() : state_(DECLARE) { } |
| 376 | 378 |
| 377 protected: | 379 protected: |
| 378 virtual v8::Handle<Boolean> Has(Local<String> key) { | 380 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 379 switch (state_) { | 381 switch (state_) { |
| 380 case DECLARE: | 382 case DECLARE: |
| 381 // Force declaration by returning that the | 383 // Force declaration by returning that the |
| 382 // property is absent. | 384 // property is absent. |
| 383 state_ = INITIALIZE_IF_ASSIGN; | 385 state_ = INITIALIZE_IF_ASSIGN; |
| 384 return False(); | 386 return Handle<Integer>(); |
| 385 case INITIALIZE_IF_ASSIGN: | 387 case INITIALIZE_IF_ASSIGN: |
| 386 // Return that the property is present so we only get the | 388 // Return that the property is present so we only get the |
| 387 // setter called when initializing with a value. | 389 // setter called when initializing with a value. |
| 388 state_ = UNKNOWN; | 390 state_ = UNKNOWN; |
| 389 return True(); | 391 return Integer::New(v8::None); |
| 390 default: | 392 default: |
| 391 CHECK(state_ == UNKNOWN); | 393 CHECK(state_ == UNKNOWN); |
| 392 break; | 394 break; |
| 393 } | 395 } |
| 394 // Do the lookup in the object. | 396 // Do the lookup in the object. |
| 395 return v8::Local<Boolean>(); | 397 return v8::Handle<Integer>(); |
| 396 } | 398 } |
| 397 | 399 |
| 398 private: | 400 private: |
| 399 State state_; | 401 State state_; |
| 400 }; | 402 }; |
| 401 | 403 |
| 402 | 404 |
| 403 TEST(Appearing) { | 405 TEST(Appearing) { |
| 404 HandleScope scope; | 406 HandleScope scope; |
| 405 | 407 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 enum State { | 453 enum State { |
| 452 DECLARE, | 454 DECLARE, |
| 453 DONT_DECLARE, | 455 DONT_DECLARE, |
| 454 INITIALIZE, | 456 INITIALIZE, |
| 455 UNKNOWN | 457 UNKNOWN |
| 456 }; | 458 }; |
| 457 | 459 |
| 458 ReappearingPropertyContext() : state_(DECLARE) { } | 460 ReappearingPropertyContext() : state_(DECLARE) { } |
| 459 | 461 |
| 460 protected: | 462 protected: |
| 461 virtual v8::Handle<Boolean> Has(Local<String> key) { | 463 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 462 switch (state_) { | 464 switch (state_) { |
| 463 case DECLARE: | 465 case DECLARE: |
| 464 // Force the first declaration by returning that | 466 // Force the first declaration by returning that |
| 465 // the property is absent. | 467 // the property is absent. |
| 466 state_ = DONT_DECLARE; | 468 state_ = DONT_DECLARE; |
| 467 return False(); | 469 return Handle<Integer>(); |
| 468 case DONT_DECLARE: | 470 case DONT_DECLARE: |
| 469 // Ignore the second declaration by returning | 471 // Ignore the second declaration by returning |
| 470 // that the property is already there. | 472 // that the property is already there. |
| 471 state_ = INITIALIZE; | 473 state_ = INITIALIZE; |
| 472 return True(); | 474 return Integer::New(v8::None); |
| 473 case INITIALIZE: | 475 case INITIALIZE: |
| 474 // Force an initialization by returning that | 476 // Force an initialization by returning that |
| 475 // the property is absent. This will make sure | 477 // the property is absent. This will make sure |
| 476 // that the setter is called and it will not | 478 // that the setter is called and it will not |
| 477 // lead to redeclaration conflicts (yet). | 479 // lead to redeclaration conflicts (yet). |
| 478 state_ = UNKNOWN; | 480 state_ = UNKNOWN; |
| 479 return False(); | 481 return Handle<Integer>(); |
| 480 default: | 482 default: |
| 481 CHECK(state_ == UNKNOWN); | 483 CHECK(state_ == UNKNOWN); |
| 482 break; | 484 break; |
| 483 } | 485 } |
| 484 // Do the lookup in the object. | 486 // Do the lookup in the object. |
| 485 return v8::Local<Boolean>(); | 487 return Handle<Integer>(); |
| 486 } | 488 } |
| 487 | 489 |
| 488 private: | 490 private: |
| 489 State state_; | 491 State state_; |
| 490 }; | 492 }; |
| 491 | 493 |
| 492 | 494 |
| 493 TEST(Reappearing) { | 495 TEST(Reappearing) { |
| 494 HandleScope scope; | 496 HandleScope scope; |
| 495 | 497 |
| 496 { ReappearingPropertyContext context; | 498 { ReappearingPropertyContext context; |
| 497 context.Check("const x; var x = 0", | 499 context.Check("const x; var x = 0", |
| 498 0, | 500 0, |
| 499 2, // var declaration + const initialization | 501 2, // var declaration + const initialization |
| 500 4, // 2 x declaration + 2 x initialization | 502 4, // 2 x declaration + 2 x initialization |
| 501 EXPECT_EXCEPTION); // x has already been declared! | 503 EXPECT_EXCEPTION); // x has already been declared! |
| 502 } | 504 } |
| 503 } | 505 } |
| 504 | 506 |
| 505 | 507 |
| 506 | 508 |
| 507 class ExistsInPrototypeContext: public DeclarationContext { | 509 class ExistsInPrototypeContext: public DeclarationContext { |
| 508 protected: | 510 protected: |
| 509 virtual v8::Handle<Boolean> Has(Local<String> key) { | 511 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 510 // Let it seem that the property exists in the prototype object. | 512 // Let it seem that the property exists in the prototype object. |
| 511 return True(); | 513 return Integer::New(v8::None); |
| 512 } | 514 } |
| 513 | 515 |
| 514 // Use the prototype as the holder for the interceptors. | 516 // Use the prototype as the holder for the interceptors. |
| 515 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 517 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
| 516 return function->PrototypeTemplate(); | 518 return function->PrototypeTemplate(); |
| 517 } | 519 } |
| 518 }; | 520 }; |
| 519 | 521 |
| 520 | 522 |
| 521 TEST(ExistsInPrototype) { | 523 TEST(ExistsInPrototype) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 0, | 563 0, |
| 562 1, // declaration | 564 1, // declaration |
| 563 EXPECT_RESULT, Number::New(0)); | 565 EXPECT_RESULT, Number::New(0)); |
| 564 } | 566 } |
| 565 } | 567 } |
| 566 | 568 |
| 567 | 569 |
| 568 | 570 |
| 569 class AbsentInPrototypeContext: public DeclarationContext { | 571 class AbsentInPrototypeContext: public DeclarationContext { |
| 570 protected: | 572 protected: |
| 571 virtual v8::Handle<Boolean> Has(Local<String> key) { | 573 virtual v8::Handle<Integer> Query(Local<String> key) { |
| 572 // Let it seem that the property is absent in the prototype object. | 574 // Let it seem that the property is absent in the prototype object. |
| 573 return False(); | 575 return Handle<Integer>(); |
| 574 } | 576 } |
| 575 | 577 |
| 576 // Use the prototype as the holder for the interceptors. | 578 // Use the prototype as the holder for the interceptors. |
| 577 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 579 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
| 578 return function->PrototypeTemplate(); | 580 return function->PrototypeTemplate(); |
| 579 } | 581 } |
| 580 }; | 582 }; |
| 581 | 583 |
| 582 | 584 |
| 583 TEST(AbsentInPrototype) { | 585 TEST(AbsentInPrototype) { |
| 584 HandleScope scope; | 586 HandleScope scope; |
| 585 | 587 |
| 586 { AbsentInPrototypeContext context; | 588 { AbsentInPrototypeContext context; |
| 587 context.Check("if (false) { var x = 0; }; x", | 589 context.Check("if (false) { var x = 0; }; x", |
| 588 0, | 590 0, |
| 589 0, | 591 0, |
| 590 1, // declaration | 592 1, // declaration |
| 591 EXPECT_RESULT, Undefined()); | 593 EXPECT_RESULT, Undefined()); |
| 592 } | 594 } |
| 593 } | 595 } |
| OLD | NEW |