| 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 // TODO(dcarney): remove | |
| 31 #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW | |
| 32 #define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | |
| 33 #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT | |
| 34 | |
| 35 #include "v8.h" | 30 #include "v8.h" |
| 36 | 31 |
| 37 #include "heap.h" | 32 #include "heap.h" |
| 38 #include "cctest.h" | 33 #include "cctest.h" |
| 39 | 34 |
| 40 using namespace v8; | 35 using namespace v8; |
| 41 | 36 |
| 42 | 37 |
| 43 enum Expectations { | 38 enum Expectations { |
| 44 EXPECT_RESULT, | 39 EXPECT_RESULT, |
| 45 EXPECT_EXCEPTION, | 40 EXPECT_EXCEPTION, |
| 46 EXPECT_ERROR | 41 EXPECT_ERROR |
| 47 }; | 42 }; |
| 48 | 43 |
| 49 | 44 |
| 50 // A DeclarationContext holds a reference to a v8::Context and keeps | 45 // A DeclarationContext holds a reference to a v8::Context and keeps |
| 51 // track of various declaration related counters to make it easier to | 46 // track of various declaration related counters to make it easier to |
| 52 // track if global declarations in the presence of interceptors behave | 47 // track if global declarations in the presence of interceptors behave |
| 53 // the right way. | 48 // the right way. |
| 54 class DeclarationContext { | 49 class DeclarationContext { |
| 55 public: | 50 public: |
| 56 DeclarationContext(); | 51 DeclarationContext(); |
| 57 | 52 |
| 58 virtual ~DeclarationContext() { | 53 virtual ~DeclarationContext() { |
| 59 if (is_initialized_) { | 54 if (is_initialized_) { |
| 60 context_->Exit(); | 55 Isolate* isolate = Isolate::GetCurrent(); |
| 61 context_.Dispose(context_->GetIsolate()); | 56 HandleScope scope(isolate); |
| 57 Local<Context> context = Local<Context>::New(isolate, context_); |
| 58 context->Exit(); |
| 59 context_.Dispose(isolate); |
| 62 } | 60 } |
| 63 } | 61 } |
| 64 | 62 |
| 65 void Check(const char* source, | 63 void Check(const char* source, |
| 66 int get, int set, int has, | 64 int get, int set, int has, |
| 67 Expectations expectations, | 65 Expectations expectations, |
| 68 v8::Handle<Value> value = Local<Value>()); | 66 v8::Handle<Value> value = Local<Value>()); |
| 69 | 67 |
| 70 int get_count() const { return get_count_; } | 68 int get_count() const { return get_count_; } |
| 71 int set_count() const { return set_count_; } | 69 int set_count() const { return set_count_; } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (is_initialized_) return; | 118 if (is_initialized_) return; |
| 121 Isolate* isolate = Isolate::GetCurrent(); | 119 Isolate* isolate = Isolate::GetCurrent(); |
| 122 HandleScope scope(isolate); | 120 HandleScope scope(isolate); |
| 123 Local<FunctionTemplate> function = FunctionTemplate::New(); | 121 Local<FunctionTemplate> function = FunctionTemplate::New(); |
| 124 Local<Value> data = External::New(this); | 122 Local<Value> data = External::New(this); |
| 125 GetHolder(function)->SetNamedPropertyHandler(&HandleGet, | 123 GetHolder(function)->SetNamedPropertyHandler(&HandleGet, |
| 126 &HandleSet, | 124 &HandleSet, |
| 127 &HandleQuery, | 125 &HandleQuery, |
| 128 0, 0, | 126 0, 0, |
| 129 data); | 127 data); |
| 130 context_.Reset(isolate, | 128 Local<Context> context = Context::New(isolate, |
| 131 Context::New(isolate, | 129 0, |
| 132 0, | 130 function->InstanceTemplate(), |
| 133 function->InstanceTemplate(), | 131 Local<Value>()); |
| 134 Local<Value>())); | 132 context_.Reset(isolate, context); |
| 135 context_->Enter(); | 133 context->Enter(); |
| 136 is_initialized_ = true; | 134 is_initialized_ = true; |
| 137 PostInitializeContext(Local<Context>::New(isolate, context_)); | 135 PostInitializeContext(context); |
| 138 } | 136 } |
| 139 | 137 |
| 140 | 138 |
| 141 void DeclarationContext::Check(const char* source, | 139 void DeclarationContext::Check(const char* source, |
| 142 int get, int set, int query, | 140 int get, int set, int query, |
| 143 Expectations expectations, | 141 Expectations expectations, |
| 144 v8::Handle<Value> value) { | 142 v8::Handle<Value> value) { |
| 145 InitializeIfNeeded(); | 143 InitializeIfNeeded(); |
| 146 // A retry after a GC may pollute the counts, so perform gc now | 144 // A retry after a GC may pollute the counts, so perform gc now |
| 147 // to avoid that. | 145 // to avoid that. |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 SimpleContext context; | 843 SimpleContext context; |
| 846 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); | 844 context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); |
| 847 // TODO(rossberg): All tests should actually be errors in Harmony, | 845 // TODO(rossberg): All tests should actually be errors in Harmony, |
| 848 // but we currently do not detect the cases where the first declaration | 846 // but we currently do not detect the cases where the first declaration |
| 849 // is not lexical. | 847 // is not lexical. |
| 850 context.Check(seconds[j], | 848 context.Check(seconds[j], |
| 851 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); | 849 i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); |
| 852 } | 850 } |
| 853 } | 851 } |
| 854 } | 852 } |
| OLD | NEW |