| 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 // TODO(jochen): Remove this after the setting is turned on globally. |
| 29 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 30 |
| 28 #include <stdlib.h> | 31 #include <stdlib.h> |
| 29 | 32 |
| 30 #include "src/v8.h" | 33 #include "src/v8.h" |
| 31 | 34 |
| 32 #include "src/heap/heap.h" | 35 #include "src/heap/heap.h" |
| 33 #include "test/cctest/cctest.h" | 36 #include "test/cctest/cctest.h" |
| 34 | 37 |
| 35 using namespace v8; | 38 using namespace v8; |
| 36 | 39 |
| 37 | 40 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 53 virtual ~DeclarationContext() { | 56 virtual ~DeclarationContext() { |
| 54 if (is_initialized_) { | 57 if (is_initialized_) { |
| 55 Isolate* isolate = CcTest::isolate(); | 58 Isolate* isolate = CcTest::isolate(); |
| 56 HandleScope scope(isolate); | 59 HandleScope scope(isolate); |
| 57 Local<Context> context = Local<Context>::New(isolate, context_); | 60 Local<Context> context = Local<Context>::New(isolate, context_); |
| 58 context->Exit(); | 61 context->Exit(); |
| 59 context_.Reset(); | 62 context_.Reset(); |
| 60 } | 63 } |
| 61 } | 64 } |
| 62 | 65 |
| 63 void Check(const char* source, | 66 void Check(const char* source, int get, int set, int has, |
| 64 int get, int set, int has, | |
| 65 Expectations expectations, | 67 Expectations expectations, |
| 66 v8::Handle<Value> value = Local<Value>()); | 68 v8::Local<Value> value = Local<Value>()); |
| 67 | 69 |
| 68 int get_count() const { return get_count_; } | 70 int get_count() const { return get_count_; } |
| 69 int set_count() const { return set_count_; } | 71 int set_count() const { return set_count_; } |
| 70 int query_count() const { return query_count_; } | 72 int query_count() const { return query_count_; } |
| 71 | 73 |
| 72 protected: | 74 protected: |
| 73 virtual v8::Handle<Value> Get(Local<Name> key); | 75 virtual v8::Local<Value> Get(Local<Name> key); |
| 74 virtual v8::Handle<Value> Set(Local<Name> key, Local<Value> value); | 76 virtual v8::Local<Value> Set(Local<Name> key, Local<Value> value); |
| 75 virtual v8::Handle<Integer> Query(Local<Name> key); | 77 virtual v8::Local<Integer> Query(Local<Name> key); |
| 76 | 78 |
| 77 void InitializeIfNeeded(); | 79 void InitializeIfNeeded(); |
| 78 | 80 |
| 79 // Perform optional initialization steps on the context after it has | 81 // Perform optional initialization steps on the context after it has |
| 80 // been created. Defaults to none but may be overwritten. | 82 // been created. Defaults to none but may be overwritten. |
| 81 virtual void PostInitializeContext(Handle<Context> context) {} | 83 virtual void PostInitializeContext(Local<Context> context) {} |
| 82 | 84 |
| 83 // Get the holder for the interceptor. Default to the instance template | 85 // Get the holder for the interceptor. Default to the instance template |
| 84 // but may be overwritten. | 86 // but may be overwritten. |
| 85 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 87 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
| 86 return function->InstanceTemplate(); | 88 return function->InstanceTemplate(); |
| 87 } | 89 } |
| 88 | 90 |
| 89 // The handlers are called as static functions that forward | 91 // The handlers are called as static functions that forward |
| 90 // to the instance specific virtual methods. | 92 // to the instance specific virtual methods. |
| 91 static void HandleGet(Local<Name> key, | 93 static void HandleGet(Local<Name> key, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 context->Enter(); | 133 context->Enter(); |
| 132 is_initialized_ = true; | 134 is_initialized_ = true; |
| 133 // Reset counts. Bootstrapping might have called into the interceptor. | 135 // Reset counts. Bootstrapping might have called into the interceptor. |
| 134 get_count_ = 0; | 136 get_count_ = 0; |
| 135 set_count_ = 0; | 137 set_count_ = 0; |
| 136 query_count_ = 0; | 138 query_count_ = 0; |
| 137 PostInitializeContext(context); | 139 PostInitializeContext(context); |
| 138 } | 140 } |
| 139 | 141 |
| 140 | 142 |
| 141 void DeclarationContext::Check(const char* source, | 143 void DeclarationContext::Check(const char* source, int get, int set, int query, |
| 142 int get, int set, int query, | |
| 143 Expectations expectations, | 144 Expectations expectations, |
| 144 v8::Handle<Value> value) { | 145 v8::Local<Value> value) { |
| 145 InitializeIfNeeded(); | 146 InitializeIfNeeded(); |
| 146 // A retry after a GC may pollute the counts, so perform gc now | 147 // A retry after a GC may pollute the counts, so perform gc now |
| 147 // to avoid that. | 148 // to avoid that. |
| 148 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE); | 149 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE); |
| 149 HandleScope scope(CcTest::isolate()); | 150 HandleScope scope(CcTest::isolate()); |
| 150 TryCatch catcher(CcTest::isolate()); | 151 TryCatch catcher(CcTest::isolate()); |
| 151 catcher.SetVerbose(true); | 152 catcher.SetVerbose(true); |
| 152 Local<Script> script = | 153 Local<Context> context = CcTest::isolate()->GetCurrentContext(); |
| 153 Script::Compile(String::NewFromUtf8(CcTest::isolate(), source)); | 154 MaybeLocal<Script> script = Script::Compile( |
| 155 context, |
| 156 String::NewFromUtf8(CcTest::isolate(), source, v8::NewStringType::kNormal) |
| 157 .ToLocalChecked()); |
| 154 if (expectations == EXPECT_ERROR) { | 158 if (expectations == EXPECT_ERROR) { |
| 155 CHECK(script.IsEmpty()); | 159 CHECK(script.IsEmpty()); |
| 156 return; | 160 return; |
| 157 } | 161 } |
| 158 CHECK(!script.IsEmpty()); | 162 CHECK(!script.IsEmpty()); |
| 159 Local<Value> result = script->Run(); | 163 MaybeLocal<Value> result = script.ToLocalChecked()->Run(context); |
| 160 CHECK_EQ(get, get_count()); | 164 CHECK_EQ(get, get_count()); |
| 161 CHECK_EQ(set, set_count()); | 165 CHECK_EQ(set, set_count()); |
| 162 CHECK_EQ(query, query_count()); | 166 CHECK_EQ(query, query_count()); |
| 163 if (expectations == EXPECT_RESULT) { | 167 if (expectations == EXPECT_RESULT) { |
| 164 CHECK(!catcher.HasCaught()); | 168 CHECK(!catcher.HasCaught()); |
| 165 if (!value.IsEmpty()) { | 169 if (!value.IsEmpty()) { |
| 166 CHECK(value->Equals(result)); | 170 CHECK(value->Equals(context, result.ToLocalChecked()).FromJust()); |
| 167 } | 171 } |
| 168 } else { | 172 } else { |
| 169 CHECK(expectations == EXPECT_EXCEPTION); | 173 CHECK(expectations == EXPECT_EXCEPTION); |
| 170 CHECK(catcher.HasCaught()); | 174 CHECK(catcher.HasCaught()); |
| 171 if (!value.IsEmpty()) { | 175 if (!value.IsEmpty()) { |
| 172 CHECK(value->Equals(catcher.Exception())); | 176 CHECK(value->Equals(context, catcher.Exception()).FromJust()); |
| 173 } | 177 } |
| 174 } | 178 } |
| 175 // Clean slate for the next test. | 179 // Clean slate for the next test. |
| 176 CcTest::heap()->CollectAllAvailableGarbage(); | 180 CcTest::heap()->CollectAllAvailableGarbage(); |
| 177 } | 181 } |
| 178 | 182 |
| 179 | 183 |
| 180 void DeclarationContext::HandleGet( | 184 void DeclarationContext::HandleGet( |
| 181 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { | 185 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 182 DeclarationContext* context = GetInstance(info.Data()); | 186 DeclarationContext* context = GetInstance(info.Data()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 201 info.GetReturnValue().Set(context->Query(key)); | 205 info.GetReturnValue().Set(context->Query(key)); |
| 202 } | 206 } |
| 203 | 207 |
| 204 | 208 |
| 205 DeclarationContext* DeclarationContext::GetInstance(Local<Value> data) { | 209 DeclarationContext* DeclarationContext::GetInstance(Local<Value> data) { |
| 206 void* value = Local<External>::Cast(data)->Value(); | 210 void* value = Local<External>::Cast(data)->Value(); |
| 207 return static_cast<DeclarationContext*>(value); | 211 return static_cast<DeclarationContext*>(value); |
| 208 } | 212 } |
| 209 | 213 |
| 210 | 214 |
| 211 v8::Handle<Value> DeclarationContext::Get(Local<Name> key) { | 215 v8::Local<Value> DeclarationContext::Get(Local<Name> key) { |
| 212 return v8::Handle<Value>(); | 216 return v8::Local<Value>(); |
| 213 } | 217 } |
| 214 | 218 |
| 215 | 219 |
| 216 v8::Handle<Value> DeclarationContext::Set(Local<Name> key, Local<Value> value) { | 220 v8::Local<Value> DeclarationContext::Set(Local<Name> key, Local<Value> value) { |
| 217 return v8::Handle<Value>(); | 221 return v8::Local<Value>(); |
| 218 } | 222 } |
| 219 | 223 |
| 220 | 224 |
| 221 v8::Handle<Integer> DeclarationContext::Query(Local<Name> key) { | 225 v8::Local<Integer> DeclarationContext::Query(Local<Name> key) { |
| 222 return v8::Handle<Integer>(); | 226 return v8::Local<Integer>(); |
| 223 } | 227 } |
| 224 | 228 |
| 225 | 229 |
| 226 // Test global declaration of a property the interceptor doesn't know | 230 // Test global declaration of a property the interceptor doesn't know |
| 227 // about and doesn't handle. | 231 // about and doesn't handle. |
| 228 TEST(Unknown) { | 232 TEST(Unknown) { |
| 229 HandleScope scope(CcTest::isolate()); | 233 HandleScope scope(CcTest::isolate()); |
| 230 v8::V8::Initialize(); | 234 v8::V8::Initialize(); |
| 231 | 235 |
| 232 { DeclarationContext context; | 236 { DeclarationContext context; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 261 1, // access | 265 1, // access |
| 262 0, | 266 0, |
| 263 0, | 267 0, |
| 264 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 268 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); |
| 265 } | 269 } |
| 266 } | 270 } |
| 267 | 271 |
| 268 | 272 |
| 269 class AbsentPropertyContext: public DeclarationContext { | 273 class AbsentPropertyContext: public DeclarationContext { |
| 270 protected: | 274 protected: |
| 271 virtual v8::Handle<Integer> Query(Local<Name> key) { | 275 virtual v8::Local<Integer> Query(Local<Name> key) { |
| 272 return v8::Handle<Integer>(); | 276 return v8::Local<Integer>(); |
| 273 } | 277 } |
| 274 }; | 278 }; |
| 275 | 279 |
| 276 | 280 |
| 277 TEST(Absent) { | 281 TEST(Absent) { |
| 278 v8::Isolate* isolate = CcTest::isolate(); | 282 v8::Isolate* isolate = CcTest::isolate(); |
| 279 v8::V8::Initialize(); | 283 v8::V8::Initialize(); |
| 280 HandleScope scope(isolate); | 284 HandleScope scope(isolate); |
| 281 | 285 |
| 282 { AbsentPropertyContext context; | 286 { AbsentPropertyContext context; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 public: | 329 public: |
| 326 enum State { | 330 enum State { |
| 327 DECLARE, | 331 DECLARE, |
| 328 INITIALIZE_IF_ASSIGN, | 332 INITIALIZE_IF_ASSIGN, |
| 329 UNKNOWN | 333 UNKNOWN |
| 330 }; | 334 }; |
| 331 | 335 |
| 332 AppearingPropertyContext() : state_(DECLARE) { } | 336 AppearingPropertyContext() : state_(DECLARE) { } |
| 333 | 337 |
| 334 protected: | 338 protected: |
| 335 virtual v8::Handle<Integer> Query(Local<Name> key) { | 339 virtual v8::Local<Integer> Query(Local<Name> key) { |
| 336 switch (state_) { | 340 switch (state_) { |
| 337 case DECLARE: | 341 case DECLARE: |
| 338 // Force declaration by returning that the | 342 // Force declaration by returning that the |
| 339 // property is absent. | 343 // property is absent. |
| 340 state_ = INITIALIZE_IF_ASSIGN; | 344 state_ = INITIALIZE_IF_ASSIGN; |
| 341 return Handle<Integer>(); | 345 return Local<Integer>(); |
| 342 case INITIALIZE_IF_ASSIGN: | 346 case INITIALIZE_IF_ASSIGN: |
| 343 // Return that the property is present so we only get the | 347 // Return that the property is present so we only get the |
| 344 // setter called when initializing with a value. | 348 // setter called when initializing with a value. |
| 345 state_ = UNKNOWN; | 349 state_ = UNKNOWN; |
| 346 return Integer::New(isolate(), v8::None); | 350 return Integer::New(isolate(), v8::None); |
| 347 default: | 351 default: |
| 348 CHECK(state_ == UNKNOWN); | 352 CHECK(state_ == UNKNOWN); |
| 349 break; | 353 break; |
| 350 } | 354 } |
| 351 // Do the lookup in the object. | 355 // Do the lookup in the object. |
| 352 return v8::Handle<Integer>(); | 356 return v8::Local<Integer>(); |
| 353 } | 357 } |
| 354 | 358 |
| 355 private: | 359 private: |
| 356 State state_; | 360 State state_; |
| 357 }; | 361 }; |
| 358 | 362 |
| 359 | 363 |
| 360 TEST(Appearing) { | 364 TEST(Appearing) { |
| 361 v8::V8::Initialize(); | 365 v8::V8::Initialize(); |
| 362 HandleScope scope(CcTest::isolate()); | 366 HandleScope scope(CcTest::isolate()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 0, 0, EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 398 0, 0, EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); |
| 395 } | 399 } |
| 396 } | 400 } |
| 397 | 401 |
| 398 | 402 |
| 399 | 403 |
| 400 class ExistsInPrototypeContext: public DeclarationContext { | 404 class ExistsInPrototypeContext: public DeclarationContext { |
| 401 public: | 405 public: |
| 402 ExistsInPrototypeContext() { InitializeIfNeeded(); } | 406 ExistsInPrototypeContext() { InitializeIfNeeded(); } |
| 403 protected: | 407 protected: |
| 404 virtual v8::Handle<Integer> Query(Local<Name> key) { | 408 virtual v8::Local<Integer> Query(Local<Name> key) { |
| 405 // Let it seem that the property exists in the prototype object. | 409 // Let it seem that the property exists in the prototype object. |
| 406 return Integer::New(isolate(), v8::None); | 410 return Integer::New(isolate(), v8::None); |
| 407 } | 411 } |
| 408 | 412 |
| 409 // Use the prototype as the holder for the interceptors. | 413 // Use the prototype as the holder for the interceptors. |
| 410 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 414 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
| 411 return function->PrototypeTemplate(); | 415 return function->PrototypeTemplate(); |
| 412 } | 416 } |
| 413 }; | 417 }; |
| 414 | 418 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 0, | 457 0, |
| 454 0, | 458 0, |
| 455 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 459 EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); |
| 456 } | 460 } |
| 457 } | 461 } |
| 458 | 462 |
| 459 | 463 |
| 460 | 464 |
| 461 class AbsentInPrototypeContext: public DeclarationContext { | 465 class AbsentInPrototypeContext: public DeclarationContext { |
| 462 protected: | 466 protected: |
| 463 virtual v8::Handle<Integer> Query(Local<Name> key) { | 467 virtual v8::Local<Integer> Query(Local<Name> key) { |
| 464 // Let it seem that the property is absent in the prototype object. | 468 // Let it seem that the property is absent in the prototype object. |
| 465 return Handle<Integer>(); | 469 return Local<Integer>(); |
| 466 } | 470 } |
| 467 | 471 |
| 468 // Use the prototype as the holder for the interceptors. | 472 // Use the prototype as the holder for the interceptors. |
| 469 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 473 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
| 470 return function->PrototypeTemplate(); | 474 return function->PrototypeTemplate(); |
| 471 } | 475 } |
| 472 }; | 476 }; |
| 473 | 477 |
| 474 | 478 |
| 475 TEST(AbsentInPrototype) { | 479 TEST(AbsentInPrototype) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 488 | 492 |
| 489 | 493 |
| 490 class ExistsInHiddenPrototypeContext: public DeclarationContext { | 494 class ExistsInHiddenPrototypeContext: public DeclarationContext { |
| 491 public: | 495 public: |
| 492 ExistsInHiddenPrototypeContext() { | 496 ExistsInHiddenPrototypeContext() { |
| 493 hidden_proto_ = FunctionTemplate::New(CcTest::isolate()); | 497 hidden_proto_ = FunctionTemplate::New(CcTest::isolate()); |
| 494 hidden_proto_->SetHiddenPrototype(true); | 498 hidden_proto_->SetHiddenPrototype(true); |
| 495 } | 499 } |
| 496 | 500 |
| 497 protected: | 501 protected: |
| 498 virtual v8::Handle<Integer> Query(Local<Name> key) { | 502 virtual v8::Local<Integer> Query(Local<Name> key) { |
| 499 // Let it seem that the property exists in the hidden prototype object. | 503 // Let it seem that the property exists in the hidden prototype object. |
| 500 return Integer::New(isolate(), v8::None); | 504 return Integer::New(isolate(), v8::None); |
| 501 } | 505 } |
| 502 | 506 |
| 503 // Install the hidden prototype after the global object has been created. | 507 // Install the hidden prototype after the global object has been created. |
| 504 virtual void PostInitializeContext(Handle<Context> context) { | 508 virtual void PostInitializeContext(Local<Context> context) { |
| 505 Local<Object> global_object = context->Global(); | 509 Local<Object> global_object = context->Global(); |
| 506 Local<Object> hidden_proto = hidden_proto_->GetFunction()->NewInstance(); | 510 Local<Object> hidden_proto = hidden_proto_->GetFunction(context) |
| 511 .ToLocalChecked() |
| 512 ->NewInstance(context) |
| 513 .ToLocalChecked(); |
| 507 Local<Object> inner_global = | 514 Local<Object> inner_global = |
| 508 Local<Object>::Cast(global_object->GetPrototype()); | 515 Local<Object>::Cast(global_object->GetPrototype()); |
| 509 inner_global->SetPrototype(hidden_proto); | 516 inner_global->SetPrototype(context, hidden_proto).FromJust(); |
| 510 } | 517 } |
| 511 | 518 |
| 512 // Use the hidden prototype as the holder for the interceptors. | 519 // Use the hidden prototype as the holder for the interceptors. |
| 513 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 520 virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |
| 514 return hidden_proto_->InstanceTemplate(); | 521 return hidden_proto_->InstanceTemplate(); |
| 515 } | 522 } |
| 516 | 523 |
| 517 private: | 524 private: |
| 518 Local<FunctionTemplate> hidden_proto_; | 525 Local<FunctionTemplate> hidden_proto_; |
| 519 }; | 526 }; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 SimpleContext() | 567 SimpleContext() |
| 561 : handle_scope_(CcTest::isolate()), | 568 : handle_scope_(CcTest::isolate()), |
| 562 context_(Context::New(CcTest::isolate())) { | 569 context_(Context::New(CcTest::isolate())) { |
| 563 context_->Enter(); | 570 context_->Enter(); |
| 564 } | 571 } |
| 565 | 572 |
| 566 ~SimpleContext() { | 573 ~SimpleContext() { |
| 567 context_->Exit(); | 574 context_->Exit(); |
| 568 } | 575 } |
| 569 | 576 |
| 570 void Check(const char* source, | 577 void Check(const char* source, Expectations expectations, |
| 571 Expectations expectations, | 578 v8::Local<Value> value = Local<Value>()) { |
| 572 v8::Handle<Value> value = Local<Value>()) { | |
| 573 HandleScope scope(context_->GetIsolate()); | 579 HandleScope scope(context_->GetIsolate()); |
| 574 TryCatch catcher(context_->GetIsolate()); | 580 TryCatch catcher(context_->GetIsolate()); |
| 575 catcher.SetVerbose(true); | 581 catcher.SetVerbose(true); |
| 576 Local<Script> script = | 582 MaybeLocal<Script> script = Script::Compile( |
| 577 Script::Compile(String::NewFromUtf8(context_->GetIsolate(), source)); | 583 context_, String::NewFromUtf8(context_->GetIsolate(), source, |
| 584 v8::NewStringType::kNormal) |
| 585 .ToLocalChecked()); |
| 578 if (expectations == EXPECT_ERROR) { | 586 if (expectations == EXPECT_ERROR) { |
| 579 CHECK(script.IsEmpty()); | 587 CHECK(script.IsEmpty()); |
| 580 return; | 588 return; |
| 581 } | 589 } |
| 582 CHECK(!script.IsEmpty()); | 590 CHECK(!script.IsEmpty()); |
| 583 Local<Value> result = script->Run(); | 591 MaybeLocal<Value> result = script.ToLocalChecked()->Run(context_); |
| 584 if (expectations == EXPECT_RESULT) { | 592 if (expectations == EXPECT_RESULT) { |
| 585 CHECK(!catcher.HasCaught()); | 593 CHECK(!catcher.HasCaught()); |
| 586 if (!value.IsEmpty()) { | 594 if (!value.IsEmpty()) { |
| 587 CHECK(value->Equals(result)); | 595 CHECK(value->Equals(context_, result.ToLocalChecked()).FromJust()); |
| 588 } | 596 } |
| 589 } else { | 597 } else { |
| 590 CHECK(expectations == EXPECT_EXCEPTION); | 598 CHECK(expectations == EXPECT_EXCEPTION); |
| 591 CHECK(catcher.HasCaught()); | 599 CHECK(catcher.HasCaught()); |
| 592 if (!value.IsEmpty()) { | 600 if (!value.IsEmpty()) { |
| 593 CHECK(value->Equals(catcher.Exception())); | 601 CHECK(value->Equals(context_, catcher.Exception()).FromJust()); |
| 594 } | 602 } |
| 595 } | 603 } |
| 596 } | 604 } |
| 597 | 605 |
| 598 private: | 606 private: |
| 599 HandleScope handle_scope_; | 607 HandleScope handle_scope_; |
| 600 Local<Context> context_; | 608 Local<Context> context_; |
| 601 }; | 609 }; |
| 602 | 610 |
| 603 | 611 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 } | 902 } |
| 895 } | 903 } |
| 896 } | 904 } |
| 897 | 905 |
| 898 | 906 |
| 899 TEST(CrossScriptDynamicLookup) { | 907 TEST(CrossScriptDynamicLookup) { |
| 900 HandleScope handle_scope(CcTest::isolate()); | 908 HandleScope handle_scope(CcTest::isolate()); |
| 901 | 909 |
| 902 { | 910 { |
| 903 SimpleContext context; | 911 SimpleContext context; |
| 904 Local<String> undefined_string = String::NewFromUtf8( | 912 Local<String> undefined_string = |
| 905 CcTest::isolate(), "undefined", String::kInternalizedString); | 913 String::NewFromUtf8(CcTest::isolate(), "undefined", |
| 906 Local<String> number_string = String::NewFromUtf8( | 914 v8::NewStringType::kInternalized) |
| 907 CcTest::isolate(), "number", String::kInternalizedString); | 915 .ToLocalChecked(); |
| 916 Local<String> number_string = |
| 917 String::NewFromUtf8(CcTest::isolate(), "number", |
| 918 v8::NewStringType::kInternalized) |
| 919 .ToLocalChecked(); |
| 908 | 920 |
| 909 context.Check( | 921 context.Check( |
| 910 "function f(o) { with(o) { return x; } }" | 922 "function f(o) { with(o) { return x; } }" |
| 911 "function g(o) { with(o) { x = 15; } }" | 923 "function g(o) { with(o) { x = 15; } }" |
| 912 "function h(o) { with(o) { return typeof x; } }", | 924 "function h(o) { with(o) { return typeof x; } }", |
| 913 EXPECT_RESULT, Undefined(CcTest::isolate())); | 925 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 914 context.Check("h({})", EXPECT_RESULT, undefined_string); | 926 context.Check("h({})", EXPECT_RESULT, undefined_string); |
| 915 context.Check( | 927 context.Check( |
| 916 "'use strict';" | 928 "'use strict';" |
| 917 "let x = 1;" | 929 "let x = 1;" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 EXPECT_EXCEPTION); | 979 EXPECT_EXCEPTION); |
| 968 } | 980 } |
| 969 } | 981 } |
| 970 | 982 |
| 971 | 983 |
| 972 TEST(CrossScriptStaticLookupUndeclared) { | 984 TEST(CrossScriptStaticLookupUndeclared) { |
| 973 HandleScope handle_scope(CcTest::isolate()); | 985 HandleScope handle_scope(CcTest::isolate()); |
| 974 | 986 |
| 975 { | 987 { |
| 976 SimpleContext context; | 988 SimpleContext context; |
| 977 Local<String> undefined_string = String::NewFromUtf8( | 989 Local<String> undefined_string = |
| 978 CcTest::isolate(), "undefined", String::kInternalizedString); | 990 String::NewFromUtf8(CcTest::isolate(), "undefined", |
| 979 Local<String> number_string = String::NewFromUtf8( | 991 v8::NewStringType::kInternalized) |
| 980 CcTest::isolate(), "number", String::kInternalizedString); | 992 .ToLocalChecked(); |
| 993 Local<String> number_string = |
| 994 String::NewFromUtf8(CcTest::isolate(), "number", |
| 995 v8::NewStringType::kInternalized) |
| 996 .ToLocalChecked(); |
| 981 | 997 |
| 982 context.Check( | 998 context.Check( |
| 983 "function f(o) { return x; }" | 999 "function f(o) { return x; }" |
| 984 "function g(v) { x = v; }" | 1000 "function g(v) { x = v; }" |
| 985 "function h(o) { return typeof x; }", | 1001 "function h(o) { return typeof x; }", |
| 986 EXPECT_RESULT, Undefined(CcTest::isolate())); | 1002 EXPECT_RESULT, Undefined(CcTest::isolate())); |
| 987 context.Check("h({})", EXPECT_RESULT, undefined_string); | 1003 context.Check("h({})", EXPECT_RESULT, undefined_string); |
| 988 context.Check( | 1004 context.Check( |
| 989 "'use strict';" | 1005 "'use strict';" |
| 990 "let x = 1;" | 1006 "let x = 1;" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 Undefined(CcTest::isolate())); | 1261 Undefined(CcTest::isolate())); |
| 1246 for (int i = 0; i < 4; i++) { | 1262 for (int i = 0; i < 4; i++) { |
| 1247 context.Check("f()", EXPECT_EXCEPTION); | 1263 context.Check("f()", EXPECT_EXCEPTION); |
| 1248 } | 1264 } |
| 1249 context.Check("%OptimizeFunctionOnNextCall(f);", EXPECT_RESULT, | 1265 context.Check("%OptimizeFunctionOnNextCall(f);", EXPECT_RESULT, |
| 1250 Undefined(CcTest::isolate())); | 1266 Undefined(CcTest::isolate())); |
| 1251 | 1267 |
| 1252 context.Check("'use strict'; f(); let x = 2; x", EXPECT_EXCEPTION); | 1268 context.Check("'use strict'; f(); let x = 2; x", EXPECT_EXCEPTION); |
| 1253 } | 1269 } |
| 1254 } | 1270 } |
| OLD | NEW |