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

Side by Side Diff: test/cctest/test-object-observe.cc

Issue 733483003: Add a cctest for using a C++ FunctionCallback as an Object.observe observer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 notifier); 755 notifier);
756 CompileRun("var obj2 = {};" 756 CompileRun("var obj2 = {};"
757 "var notifier2 = Object.getNotifier(obj2);" 757 "var notifier2 = Object.getNotifier(obj2);"
758 "notifier2.performChange.call(" 758 "notifier2.performChange.call("
759 "notifier, 'foo', function(){})"); 759 "notifier, 'foo', function(){})");
760 } 760 }
761 761
762 CcTest::isolate()->ContextDisposedNotification(); 762 CcTest::isolate()->ContextDisposedNotification();
763 CheckSurvivingGlobalObjectsCount(1); 763 CheckSurvivingGlobalObjectsCount(1);
764 } 764 }
765
766
767 static void ObserverCallback(const FunctionCallbackInfo<Value>& args) {
768 *static_cast<int*>(Handle<External>::Cast(args.Data())->Value()) =
769 Handle<Array>::Cast(args[0])->Length();
770 }
771
772
773 TEST(ObjectObserveCallsCppFunction) {
774 Isolate* isolate = CcTest::isolate();
775 HandleScope scope(isolate);
776 LocalContext context(isolate);
777 int numRecordsSent = 0;
778 Handle<Function> observer =
779 Function::New(CcTest::isolate(), ObserverCallback,
780 External::New(isolate, &numRecordsSent));
781 context->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "observer"),
782 observer);
783 CompileRun(
784 "var obj = {};"
785 "Object.observe(obj, observer);"
786 "obj.foo = 1;"
787 "obj.bar = 2;");
788 CHECK_EQ(2, numRecordsSent);
789 }
790
791
792 TEST(ObjectObserveCallsFunctionTemplateInstance) {
793 Isolate* isolate = CcTest::isolate();
794 HandleScope scope(isolate);
795 LocalContext context(isolate);
796 int numRecordsSent = 0;
797 Handle<FunctionTemplate> tmpl = FunctionTemplate::New(
798 isolate, ObserverCallback, External::New(isolate, &numRecordsSent));
799 context->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "observer"),
800 tmpl->GetFunction());
801 CompileRun(
802 "var obj = {};"
803 "Object.observe(obj, observer);"
804 "obj.foo = 1;"
805 "obj.bar = 2;");
806 CHECK_EQ(2, numRecordsSent);
807 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698