remove GetCurrent from LocalContext

R=svenpanne@chromium.org
BUG=

Review URL: https://codereview.chromium.org/24271002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16824 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
dcarney@chromium.org 2013-09-19 10:31:04 +00:00
parent 15408ba0c9
commit c8c6cfe5fa
4 changed files with 59 additions and 44 deletions

View File

@ -220,20 +220,19 @@ class RegisterThreadedTest {
// A LocalContext holds a reference to a v8::Context.
class LocalContext {
public:
LocalContext(v8::Isolate* isolate,
v8::ExtensionConfiguration* extensions = 0,
v8::Handle<v8::ObjectTemplate> global_template =
v8::Handle<v8::ObjectTemplate>(),
v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
Initialize(isolate, extensions, global_template, global_object);
}
LocalContext(v8::ExtensionConfiguration* extensions = 0,
v8::Handle<v8::ObjectTemplate> global_template =
v8::Handle<v8::ObjectTemplate>(),
v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate,
extensions,
global_template,
global_object);
context_.Reset(isolate, context);
context->Enter();
// We can't do this later perhaps because of a fatal error.
isolate_ = context->GetIsolate();
Initialize(CcTest::isolate(), extensions, global_template, global_object);
}
virtual ~LocalContext() {
@ -253,6 +252,21 @@ class LocalContext {
}
private:
void Initialize(v8::Isolate* isolate,
v8::ExtensionConfiguration* extensions,
v8::Handle<v8::ObjectTemplate> global_template,
v8::Handle<v8::Value> global_object) {
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate,
extensions,
global_template,
global_object);
context_.Reset(isolate, context);
context->Enter();
// We can't do this later perhaps because of a fatal error.
isolate_ = isolate;
}
v8::Persistent<v8::Context> context_;
v8::Isolate* isolate_;
};

View File

@ -13364,7 +13364,7 @@ static void event_handler(const v8::JitCodeEvent* event) {
}
TEST(SetJitCodeEventHandler) {
UNINITIALIZED_TEST(SetJitCodeEventHandler) {
i::FLAG_stress_compaction = true;
i::FLAG_incremental_marking = false;
const char* script =
@ -13400,7 +13400,7 @@ TEST(SetJitCodeEventHandler) {
// different fragmented code-space pages.
const int kIterations = 10;
for (int i = 0; i < kIterations; ++i) {
LocalContext env;
LocalContext env(isolate);
i::AlwaysAllocateScope always_allocate;
SimulateFullSpace(heap->code_space());
CompileRun(script);
@ -13438,7 +13438,7 @@ TEST(SetJitCodeEventHandler) {
// request enumeration of existing code.
{
v8::HandleScope scope(isolate);
LocalContext env;
LocalContext env(isolate);
CompileRun(script);
// Now get code through initial iteration.
@ -18221,7 +18221,7 @@ UNINITIALIZED_TEST(DisposeIsolateWhenInUse) {
CHECK(isolate);
isolate->Enter();
v8::HandleScope scope(isolate);
LocalContext context;
LocalContext context(isolate);
// Run something in this isolate.
ExpectTrue("true");
v8::V8::SetFatalErrorHandler(StoringErrorCallback);
@ -18361,7 +18361,7 @@ TEST(RunTwoIsolatesOnSingleThread) {
static int CalcFibonacci(v8::Isolate* isolate, int limit) {
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope scope(isolate);
LocalContext context;
LocalContext context(isolate);
i::ScopedVector<char> code(1024);
i::OS::SNPrintF(code, "function fib(n) {"
" if (n <= 2) return 1;"

View File

@ -183,7 +183,7 @@ class IsolateLockingThreadWithLocalContext : public JoinableThread {
v8::Locker locker(isolate_);
v8::Isolate::Scope isolate_scope(isolate_);
v8::HandleScope handle_scope(isolate_);
LocalContext local_context;
LocalContext local_context(isolate_);
CHECK_EQ(isolate_, v8::internal::Isolate::Current());
CalcFibAndCheck();
}
@ -267,7 +267,7 @@ class IsolateNestedLockingThread : public JoinableThread {
v8::Locker lock(isolate_);
v8::Isolate::Scope isolate_scope(isolate_);
v8::HandleScope handle_scope(isolate_);
LocalContext local_context;
LocalContext local_context(isolate_);
{
v8::Locker another_lock(isolate_);
CalcFibAndCheck();
@ -311,7 +311,7 @@ class SeparateIsolatesLocksNonexclusiveThread : public JoinableThread {
v8::Locker lock(isolate1_);
v8::Isolate::Scope isolate_scope(isolate1_);
v8::HandleScope handle_scope(isolate1_);
LocalContext local_context;
LocalContext local_context(isolate1_);
IsolateLockingThreadWithLocalContext threadB(isolate2_);
threadB.Start();

View File

@ -58,7 +58,7 @@ class HarmonyIsolate {
TEST(PerIsolateState) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context1;
LocalContext context1(isolate.GetIsolate());
CompileRun(
"var count = 0;"
"var calls = 0;"
@ -71,20 +71,20 @@ TEST(PerIsolateState) {
"(function() { obj.foo = 'bar'; })");
Handle<Value> notify_fun2;
{
LocalContext context2;
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::New("obj"), obj);
notify_fun2 = CompileRun(
"(function() { obj.foo = 'baz'; })");
}
Handle<Value> notify_fun3;
{
LocalContext context3;
LocalContext context3(isolate.GetIsolate());
context3->Global()->Set(String::New("obj"), obj);
notify_fun3 = CompileRun(
"(function() { obj.foo = 'bat'; })");
}
{
LocalContext context4;
LocalContext context4(isolate.GetIsolate());
context4->Global()->Set(String::New("observer"), observer);
context4->Global()->Set(String::New("fun1"), notify_fun1);
context4->Global()->Set(String::New("fun2"), notify_fun2);
@ -99,7 +99,7 @@ TEST(PerIsolateState) {
TEST(EndOfMicrotaskDelivery) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
CompileRun(
"var obj = {};"
"var count = 0;"
@ -113,7 +113,7 @@ TEST(EndOfMicrotaskDelivery) {
TEST(DeliveryOrdering) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
CompileRun(
"var obj1 = {};"
"var obj2 = {};"
@ -145,7 +145,7 @@ TEST(DeliveryOrdering) {
TEST(DeliveryOrderingReentrant) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
CompileRun(
"var obj = {};"
"var reentered = false;"
@ -177,7 +177,7 @@ TEST(DeliveryOrderingReentrant) {
TEST(DeliveryOrderingDeliverChangeRecords) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
CompileRun(
"var obj = {};"
"var ordering = [];"
@ -203,14 +203,14 @@ TEST(ObjectHashTableGrowth) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
// Initializing this context sets up initial hash tables.
LocalContext context;
LocalContext context(isolate.GetIsolate());
Handle<Value> obj = CompileRun("obj = {};");
Handle<Value> observer = CompileRun(
"var ran = false;"
"(function() { ran = true })");
{
// As does initializing this context.
LocalContext context2;
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::New("obj"), obj);
context2->Global()->Set(String::New("observer"), observer);
CompileRun(
@ -231,7 +231,7 @@ TEST(ObjectHashTableGrowth) {
TEST(GlobalObjectObservation) {
HarmonyIsolate isolate;
LocalContext context;
LocalContext context(isolate.GetIsolate());
HandleScope scope(isolate.GetIsolate());
Handle<Object> global_proxy = context->Global();
Handle<Object> inner_global = global_proxy->GetPrototype().As<Object>();
@ -263,7 +263,7 @@ TEST(GlobalObjectObservation) {
// to the old context.
context->DetachGlobal();
{
LocalContext context2;
LocalContext context2(isolate.GetIsolate());
context2->DetachGlobal();
context2->ReattachGlobal(global_proxy);
CompileRun(
@ -278,7 +278,8 @@ TEST(GlobalObjectObservation) {
// Attaching by passing to Context::New
{
// Delegates to Context::New
LocalContext context3(NULL, Handle<ObjectTemplate>(), global_proxy);
LocalContext context3(
isolate.GetIsolate(), NULL, Handle<ObjectTemplate>(), global_proxy);
CompileRun(
"var records3 = [];"
"Object.observe(this, function(r) { [].push.apply(records3, r) });"
@ -330,7 +331,7 @@ static void ExpectRecords(Handle<Value> records,
TEST(APITestBasicMutation) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
Handle<Object> obj = Handle<Object>::Cast(CompileRun(
"var records = [];"
"var obj = {};"
@ -374,7 +375,7 @@ TEST(APITestBasicMutation) {
TEST(HiddenPrototypeObservation) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
Handle<FunctionTemplate> tmpl = FunctionTemplate::New();
tmpl->SetHiddenPrototype(true);
tmpl->InstanceTemplate()->Set(String::New("foo"), Number::New(75));
@ -423,7 +424,7 @@ static int NumberOfElements(i::Handle<i::JSWeakMap> map) {
TEST(ObservationWeakMap) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
CompileRun(
"var obj = {};"
"Object.observe(obj, function(){});"
@ -517,7 +518,7 @@ TEST(NamedAccessCheck) {
const AccessType types[] = { ACCESS_GET, ACCESS_HAS };
for (size_t i = 0; i < ARRAY_SIZE(types); ++i) {
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
g_access_block_type = types[i];
Handle<Object> instance = CreateAccessCheckedObject(
NamedAccessAllowUnlessBlocked, IndexedAccessAlwaysAllowed);
@ -529,7 +530,7 @@ TEST(NamedAccessCheck) {
"Object.observe(objNoCheck, observer);");
Handle<Value> obj_no_check = CompileRun("objNoCheck");
{
LocalContext context2;
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::New("obj"), instance);
context2->Global()->Set(String::New("objNoCheck"), obj_no_check);
CompileRun("var records2 = null;"
@ -564,7 +565,7 @@ TEST(IndexedAccessCheck) {
const AccessType types[] = { ACCESS_GET, ACCESS_HAS };
for (size_t i = 0; i < ARRAY_SIZE(types); ++i) {
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
g_access_block_type = types[i];
Handle<Object> instance = CreateAccessCheckedObject(
NamedAccessAlwaysAllowed, IndexedAccessAllowUnlessBlocked);
@ -576,7 +577,7 @@ TEST(IndexedAccessCheck) {
"Object.observe(objNoCheck, observer);");
Handle<Value> obj_no_check = CompileRun("objNoCheck");
{
LocalContext context2;
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::New("obj"), instance);
context2->Global()->Set(String::New("objNoCheck"), obj_no_check);
CompileRun("var records2 = null;"
@ -609,7 +610,7 @@ TEST(IndexedAccessCheck) {
TEST(SpliceAccessCheck) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
g_access_block_type = ACCESS_GET;
Handle<Object> instance = CreateAccessCheckedObject(
NamedAccessAlwaysAllowed, IndexedAccessAllowUnlessBlocked);
@ -623,7 +624,7 @@ TEST(SpliceAccessCheck) {
"Array.observe(objNoCheck, observer);");
Handle<Value> obj_no_check = CompileRun("objNoCheck");
{
LocalContext context2;
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::New("obj"), instance);
context2->Global()->Set(String::New("objNoCheck"), obj_no_check);
CompileRun("var records2 = null;"
@ -654,7 +655,7 @@ TEST(SpliceAccessCheck) {
TEST(DisallowAllForAccessKeys) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
Handle<Object> instance = CreateAccessCheckedObject(
BlockAccessKeys, IndexedAccessAlwaysAllowed);
CompileRun("var records = null;"
@ -665,7 +666,7 @@ TEST(DisallowAllForAccessKeys) {
"Object.observe(objNoCheck, observer);");
Handle<Value> obj_no_check = CompileRun("objNoCheck");
{
LocalContext context2;
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::New("obj"), instance);
context2->Global()->Set(String::New("objNoCheck"), obj_no_check);
CompileRun("var records2 = null;"
@ -692,7 +693,7 @@ TEST(DisallowAllForAccessKeys) {
TEST(AccessCheckDisallowApiModifications) {
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context;
LocalContext context(isolate.GetIsolate());
Handle<Object> instance = CreateAccessCheckedObject(
BlockAccessKeys, IndexedAccessAlwaysAllowed);
CompileRun("var records = null;"
@ -700,7 +701,7 @@ TEST(AccessCheckDisallowApiModifications) {
"var blacklist = {__block_access_keys: true};"
"Object.observe(obj, observer);");
{
LocalContext context2;
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::New("obj"), instance);
CompileRun("var records2 = null;"
"var observer2 = function(r) { records2 = r };"