| Index: test/cctest/test-object-observe.cc
|
| diff --git a/test/cctest/test-ast.cc b/test/cctest/test-object-observe.cc
|
| similarity index 55%
|
| copy from test/cctest/test-ast.cc
|
| copy to test/cctest/test-object-observe.cc
|
| index c72f87ec3dee0fcc4d356a0a45bc1dedb3c1e36b..9de47cac8e6ccf737c4b1cdc087e6fff1b11daef 100644
|
| --- a/test/cctest/test-ast.cc
|
| +++ b/test/cctest/test-object-observe.cc
|
| @@ -25,37 +25,60 @@
|
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| -#include <stdlib.h>
|
| -
|
| #include "v8.h"
|
|
|
| -#include "ast.h"
|
| #include "cctest.h"
|
|
|
| -using namespace v8::internal;
|
| -
|
| -TEST(List) {
|
| - v8::internal::V8::Initialize(NULL);
|
| - List<AstNode*>* list = new List<AstNode*>(0);
|
| - CHECK_EQ(0, list->length());
|
| +using namespace v8;
|
|
|
| - Isolate* isolate = Isolate::Current();
|
| - Zone* zone = isolate->runtime_zone();
|
| - ZoneScope zone_scope(zone, DELETE_ON_EXIT);
|
| - AstNodeFactory<AstNullVisitor> factory(isolate, zone);
|
| - AstNode* node = factory.NewEmptyStatement();
|
| - list->Add(node);
|
| - CHECK_EQ(1, list->length());
|
| - CHECK_EQ(node, list->at(0));
|
| - CHECK_EQ(node, list->last());
|
| +namespace {
|
| +// Need to create a new isolate when FLAG_harmony_object_observe is on.
|
| +class HarmonyIsolate {
|
| + public:
|
| + HarmonyIsolate() {
|
| + i::FLAG_harmony_object_observe = true;
|
| + isolate_ = Isolate::New();
|
| + isolate_->Enter();
|
| + }
|
|
|
| - const int kElements = 100;
|
| - for (int i = 0; i < kElements; i++) {
|
| - list->Add(node);
|
| + ~HarmonyIsolate() {
|
| + isolate_->Exit();
|
| + isolate_->Dispose();
|
| }
|
| - CHECK_EQ(1 + kElements, list->length());
|
|
|
| - list->Clear();
|
| - CHECK_EQ(0, list->length());
|
| - delete list;
|
| + private:
|
| + Isolate* isolate_;
|
| +};
|
| +}
|
| +
|
| +TEST(PerIsolateState) {
|
| + HarmonyIsolate isolate;
|
| + HandleScope scope;
|
| + LocalContext context1;
|
| + CompileRun(
|
| + "var count = 0;"
|
| + "var calls = 0;"
|
| + "var observer = function(records) { count = records.length; calls++ };"
|
| + "var obj = {};"
|
| + "Object.observe(obj, observer);"
|
| + "Object.notify(obj, {type: 'a'});");
|
| + Handle<Value> observer = CompileRun("observer");
|
| + Handle<Value> obj = CompileRun("obj");
|
| + {
|
| + LocalContext context2;
|
| + context2->Global()->Set(String::New("obj"), obj);
|
| + CompileRun("Object.notify(obj, {type: 'b'});");
|
| + }
|
| + {
|
| + LocalContext context3;
|
| + context3->Global()->Set(String::New("obj"), obj);
|
| + CompileRun("Object.notify(obj, {type: 'c'});");
|
| + }
|
| + {
|
| + LocalContext context4;
|
| + context4->Global()->Set(String::New("observer"), observer);
|
| + CompileRun("Object.deliverChangeRecords(observer)");
|
| + }
|
| + CHECK_EQ(1, CompileRun("calls")->Int32Value());
|
| + CHECK_EQ(3, CompileRun("count")->Int32Value());
|
| }
|
|
|