Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 | 29 |
| 30 #include "src/v8.h" | 30 #include "src/v8.h" |
| 31 | 31 |
| 32 #include "src/heap/heap.h" | 32 #include "src/heap/heap.h" |
| 33 #include "test/cctest/cctest.h" | 33 #include "test/cctest/cctest.h" |
| 34 | 34 |
| 35 using namespace v8; | 35 using namespace v8; |
| 36 | 36 |
| 37 | 37 // TODO(krasin): rename this type back to Expectations when |
| 38 enum Expectations { | 38 // https://crbug.com/630335 is fixed. Clang confuses two Expectations |
| 39 // types: here and in test-field-type-tracking.cc, which makes the | |
|
Benedikt Meurer
2016/08/10 08:09:33
How about just using an anonymous namespace?
krasin
2016/08/10 16:19:34
Done.
| |
| 40 // official Chrome build flaky. | |
| 41 enum ExpectationsCode { | |
| 39 EXPECT_RESULT, | 42 EXPECT_RESULT, |
| 40 EXPECT_EXCEPTION, | 43 EXPECT_EXCEPTION, |
| 41 EXPECT_ERROR | 44 EXPECT_ERROR |
| 42 }; | 45 }; |
| 43 | 46 |
| 44 | 47 |
| 45 // A DeclarationContext holds a reference to a v8::Context and keeps | 48 // A DeclarationContext holds a reference to a v8::Context and keeps |
| 46 // track of various declaration related counters to make it easier to | 49 // track of various declaration related counters to make it easier to |
| 47 // track if global declarations in the presence of interceptors behave | 50 // track if global declarations in the presence of interceptors behave |
| 48 // the right way. | 51 // the right way. |
| 49 class DeclarationContext { | 52 class DeclarationContext { |
| 50 public: | 53 public: |
| 51 DeclarationContext(); | 54 DeclarationContext(); |
| 52 | 55 |
| 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, int get, int set, int has, | 66 void Check(const char* source, int get, int set, int has, |
| 64 Expectations expectations, | 67 ExpectationsCode expectations, |
| 65 v8::Local<Value> value = Local<Value>()); | 68 v8::Local<Value> value = Local<Value>()); |
| 66 | 69 |
| 67 int get_count() const { return get_count_; } | 70 int get_count() const { return get_count_; } |
| 68 int set_count() const { return set_count_; } | 71 int set_count() const { return set_count_; } |
| 69 int query_count() const { return query_count_; } | 72 int query_count() const { return query_count_; } |
| 70 | 73 |
| 71 protected: | 74 protected: |
| 72 virtual v8::Local<Value> Get(Local<Name> key); | 75 virtual v8::Local<Value> Get(Local<Name> key); |
| 73 virtual v8::Local<Value> Set(Local<Name> key, Local<Value> value); | 76 virtual v8::Local<Value> Set(Local<Name> key, Local<Value> value); |
| 74 virtual v8::Local<Integer> Query(Local<Name> key); | 77 virtual v8::Local<Integer> Query(Local<Name> key); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 is_initialized_ = true; | 134 is_initialized_ = true; |
| 132 // Reset counts. Bootstrapping might have called into the interceptor. | 135 // Reset counts. Bootstrapping might have called into the interceptor. |
| 133 get_count_ = 0; | 136 get_count_ = 0; |
| 134 set_count_ = 0; | 137 set_count_ = 0; |
| 135 query_count_ = 0; | 138 query_count_ = 0; |
| 136 PostInitializeContext(context); | 139 PostInitializeContext(context); |
| 137 } | 140 } |
| 138 | 141 |
| 139 | 142 |
| 140 void DeclarationContext::Check(const char* source, int get, int set, int query, | 143 void DeclarationContext::Check(const char* source, int get, int set, int query, |
| 141 Expectations expectations, | 144 ExpectationsCode expectations, |
| 142 v8::Local<Value> value) { | 145 v8::Local<Value> value) { |
| 143 InitializeIfNeeded(); | 146 InitializeIfNeeded(); |
| 144 // 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 |
| 145 // to avoid that. | 148 // to avoid that. |
| 146 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE); | 149 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE); |
| 147 HandleScope scope(CcTest::isolate()); | 150 HandleScope scope(CcTest::isolate()); |
| 148 TryCatch catcher(CcTest::isolate()); | 151 TryCatch catcher(CcTest::isolate()); |
| 149 catcher.SetVerbose(true); | 152 catcher.SetVerbose(true); |
| 150 Local<Context> context = CcTest::isolate()->GetCurrentContext(); | 153 Local<Context> context = CcTest::isolate()->GetCurrentContext(); |
| 151 MaybeLocal<Script> script = Script::Compile( | 154 MaybeLocal<Script> script = Script::Compile( |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 SimpleContext() | 501 SimpleContext() |
| 499 : handle_scope_(CcTest::isolate()), | 502 : handle_scope_(CcTest::isolate()), |
| 500 context_(Context::New(CcTest::isolate())) { | 503 context_(Context::New(CcTest::isolate())) { |
| 501 context_->Enter(); | 504 context_->Enter(); |
| 502 } | 505 } |
| 503 | 506 |
| 504 ~SimpleContext() { | 507 ~SimpleContext() { |
| 505 context_->Exit(); | 508 context_->Exit(); |
| 506 } | 509 } |
| 507 | 510 |
| 508 void Check(const char* source, Expectations expectations, | 511 void Check(const char* source, ExpectationsCode expectations, |
| 509 v8::Local<Value> value = Local<Value>()) { | 512 v8::Local<Value> value = Local<Value>()) { |
| 510 HandleScope scope(context_->GetIsolate()); | 513 HandleScope scope(context_->GetIsolate()); |
| 511 TryCatch catcher(context_->GetIsolate()); | 514 TryCatch catcher(context_->GetIsolate()); |
| 512 catcher.SetVerbose(true); | 515 catcher.SetVerbose(true); |
| 513 MaybeLocal<Script> script = Script::Compile( | 516 MaybeLocal<Script> script = Script::Compile( |
| 514 context_, String::NewFromUtf8(context_->GetIsolate(), source, | 517 context_, String::NewFromUtf8(context_->GetIsolate(), source, |
| 515 v8::NewStringType::kNormal) | 518 v8::NewStringType::kNormal) |
| 516 .ToLocalChecked()); | 519 .ToLocalChecked()); |
| 517 if (expectations == EXPECT_ERROR) { | 520 if (expectations == EXPECT_ERROR) { |
| 518 CHECK(script.IsEmpty()); | 521 CHECK(script.IsEmpty()); |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1174 Undefined(CcTest::isolate())); | 1177 Undefined(CcTest::isolate())); |
| 1175 for (int i = 0; i < 4; i++) { | 1178 for (int i = 0; i < 4; i++) { |
| 1176 context.Check("f()", EXPECT_EXCEPTION); | 1179 context.Check("f()", EXPECT_EXCEPTION); |
| 1177 } | 1180 } |
| 1178 context.Check("%OptimizeFunctionOnNextCall(f);", EXPECT_RESULT, | 1181 context.Check("%OptimizeFunctionOnNextCall(f);", EXPECT_RESULT, |
| 1179 Undefined(CcTest::isolate())); | 1182 Undefined(CcTest::isolate())); |
| 1180 | 1183 |
| 1181 context.Check("'use strict'; f(); let x = 2; x", EXPECT_EXCEPTION); | 1184 context.Check("'use strict'; f(); let x = 2; x", EXPECT_EXCEPTION); |
| 1182 } | 1185 } |
| 1183 } | 1186 } |
| OLD | NEW |