Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: test/cctest/test-debug.cc

Issue 1428793002: Reland v8::Private and related APIs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 4634 matching lines...) Expand 10 before | Expand all | Expand 10 after
4645 v8::HandleScope scope(isolate); 4645 v8::HandleScope scope(isolate);
4646 env.ExposeDebug(); 4646 env.ExposeDebug();
4647 4647
4648 // Create an object in the global scope. 4648 // Create an object in the global scope.
4649 const char* source = "var obj = {a: 1};"; 4649 const char* source = "var obj = {a: 1};";
4650 v8::Script::Compile(v8::String::NewFromUtf8(isolate, source)) 4650 v8::Script::Compile(v8::String::NewFromUtf8(isolate, source))
4651 ->Run(); 4651 ->Run();
4652 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast( 4652 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(
4653 env->Global()->Get(v8::String::NewFromUtf8(isolate, "obj"))); 4653 env->Global()->Get(v8::String::NewFromUtf8(isolate, "obj")));
4654 // Set a hidden property on the object. 4654 // Set a hidden property on the object.
4655 obj->SetHiddenValue( 4655 obj->SetPrivate(env.context(),
4656 v8::String::NewFromUtf8(isolate, "v8::test-debug::a"), 4656 v8::Private::New(isolate, v8::String::NewFromUtf8(
4657 v8::Int32::New(isolate, 11)); 4657 isolate, "v8::test-debug::a")),
4658 v8::Int32::New(isolate, 11))
4659 .FromJust();
4658 4660
4659 // Get mirror for the object with property getter. 4661 // Get mirror for the object with property getter.
4660 CompileRun("var obj_mirror = debug.MakeMirror(obj);"); 4662 CompileRun("var obj_mirror = debug.MakeMirror(obj);");
4661 CHECK(CompileRun( 4663 CHECK(CompileRun(
4662 "obj_mirror instanceof debug.ObjectMirror")->BooleanValue()); 4664 "obj_mirror instanceof debug.ObjectMirror")->BooleanValue());
4663 CompileRun("var named_names = obj_mirror.propertyNames();"); 4665 CompileRun("var named_names = obj_mirror.propertyNames();");
4664 // There should be exactly one property. But there is also an unnamed 4666 // There should be exactly one property. But there is also an unnamed
4665 // property whose value is hidden properties dictionary. The latter 4667 // property whose value is hidden properties dictionary. The latter
4666 // property should not be in the list of reguar properties. 4668 // property should not be in the list of reguar properties.
4667 CHECK_EQ(1, CompileRun("named_names.length")->Int32Value()); 4669 CHECK_EQ(1, CompileRun("named_names.length")->Int32Value());
4668 CHECK(CompileRun("named_names[0] == 'a'")->BooleanValue()); 4670 CHECK(CompileRun("named_names[0] == 'a'")->BooleanValue());
4669 CHECK(CompileRun( 4671 CHECK(CompileRun(
4670 "obj_mirror.property('a').value().value() == 1")->BooleanValue()); 4672 "obj_mirror.property('a').value().value() == 1")->BooleanValue());
4671 4673
4672 // Object created by t0 will become hidden prototype of object 'obj'. 4674 // Object created by t0 will become hidden prototype of object 'obj'.
4673 v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); 4675 v8::Handle<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate);
4674 t0->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, "b"), 4676 t0->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, "b"),
4675 v8::Number::New(isolate, 2)); 4677 v8::Number::New(isolate, 2));
4676 t0->SetHiddenPrototype(true); 4678 t0->SetHiddenPrototype(true);
4677 v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 4679 v8::Handle<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
4678 t1->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, "c"), 4680 t1->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate, "c"),
4679 v8::Number::New(isolate, 3)); 4681 v8::Number::New(isolate, 3));
4680 4682
4681 // Create proto objects, add hidden properties to them and set them on 4683 // Create proto objects, add hidden properties to them and set them on
4682 // the global object. 4684 // the global object.
4683 v8::Handle<v8::Object> protoObj = t0->GetFunction()->NewInstance(); 4685 v8::Handle<v8::Object> protoObj = t0->GetFunction()->NewInstance();
4684 protoObj->SetHiddenValue( 4686 protoObj->SetPrivate(
4685 v8::String::NewFromUtf8(isolate, "v8::test-debug::b"), 4687 env.context(),
4686 v8::Int32::New(isolate, 12)); 4688 v8::Private::New(isolate, v8::String::NewFromUtf8(
4689 isolate, "v8::test-debug::b")),
4690 v8::Int32::New(isolate, 12))
4691 .FromJust();
4687 env->Global()->Set(v8::String::NewFromUtf8(isolate, "protoObj"), 4692 env->Global()->Set(v8::String::NewFromUtf8(isolate, "protoObj"),
4688 protoObj); 4693 protoObj);
4689 v8::Handle<v8::Object> grandProtoObj = t1->GetFunction()->NewInstance(); 4694 v8::Handle<v8::Object> grandProtoObj = t1->GetFunction()->NewInstance();
4690 grandProtoObj->SetHiddenValue( 4695 grandProtoObj->SetPrivate(
4691 v8::String::NewFromUtf8(isolate, "v8::test-debug::c"), 4696 env.context(),
4692 v8::Int32::New(isolate, 13)); 4697 v8::Private::New(isolate, v8::String::NewFromUtf8(
4693 env->Global()->Set( 4698 isolate, "v8::test-debug::c")),
4694 v8::String::NewFromUtf8(isolate, "grandProtoObj"), 4699 v8::Int32::New(isolate, 13))
4695 grandProtoObj); 4700 .FromJust();
4701 env->Global()->Set(v8::String::NewFromUtf8(isolate, "grandProtoObj"),
4702 grandProtoObj);
4696 4703
4697 // Setting prototypes: obj->protoObj->grandProtoObj 4704 // Setting prototypes: obj->protoObj->grandProtoObj
4698 protoObj->Set(v8::String::NewFromUtf8(isolate, "__proto__"), 4705 protoObj->Set(v8::String::NewFromUtf8(isolate, "__proto__"),
4699 grandProtoObj); 4706 grandProtoObj);
4700 obj->Set(v8::String::NewFromUtf8(isolate, "__proto__"), protoObj); 4707 obj->Set(v8::String::NewFromUtf8(isolate, "__proto__"), protoObj);
4701 4708
4702 // Get mirror for the object with property getter. 4709 // Get mirror for the object with property getter.
4703 CompileRun("var obj_mirror = debug.MakeMirror(obj);"); 4710 CompileRun("var obj_mirror = debug.MakeMirror(obj);");
4704 CHECK(CompileRun( 4711 CHECK(CompileRun(
4705 "obj_mirror instanceof debug.ObjectMirror")->BooleanValue()); 4712 "obj_mirror instanceof debug.ObjectMirror")->BooleanValue());
(...skipping 2940 matching lines...) Expand 10 before | Expand all | Expand 10 after
7646 CompileRun("function foo() {}; foo();"); 7653 CompileRun("function foo() {}; foo();");
7647 --after_compile_handler_depth; 7654 --after_compile_handler_depth;
7648 } 7655 }
7649 7656
7650 7657
7651 TEST(NoInterruptsInDebugListener) { 7658 TEST(NoInterruptsInDebugListener) {
7652 DebugLocalContext env; 7659 DebugLocalContext env;
7653 v8::Debug::SetDebugEventListener(NoInterruptsOnDebugEvent); 7660 v8::Debug::SetDebugEventListener(NoInterruptsOnDebugEvent);
7654 CompileRun("void(0);"); 7661 CompileRun("void(0);");
7655 } 7662 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698