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

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

Issue 6293002: Port r6301 to 2.5 branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/2.5/
Patch Set: Created 9 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « src/version.cc ('k') | 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 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 807
808 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); 808 Local<Value> result = v8_compile("(new obj()).toString()")->Run();
809 CHECK_EQ(v8_str("[object funky]"), result); 809 CHECK_EQ(v8_str("[object funky]"), result);
810 810
811 result = v8_compile("(new obj()).m")->Run(); 811 result = v8_compile("(new obj()).m")->Run();
812 CHECK_EQ(239, result->Int32Value()); 812 CHECK_EQ(239, result->Int32Value());
813 } 813 }
814 } 814 }
815 815
816 816
817 static void* expected_ptr;
818 static v8::Handle<v8::Value> callback(const v8::Arguments& args) {
819 void* ptr = v8::External::Unwrap(args.Data());
820 CHECK_EQ(expected_ptr, ptr);
821 return v8::Boolean::New(true);
822 }
823
824
825 static void TestExternalPointerWrapping() {
826 v8::HandleScope scope;
827 LocalContext env;
828
829 v8::Handle<v8::Value> data = v8::External::Wrap(expected_ptr);
830
831 v8::Handle<v8::Object> obj = v8::Object::New();
832 obj->Set(v8_str("func"),
833 v8::FunctionTemplate::New(callback, data)->GetFunction());
834 env->Global()->Set(v8_str("obj"), obj);
835
836 CHECK(CompileRun(
837 "function foo() {\n"
838 " for (var i = 0; i < 13; i++) obj.func();\n"
839 "}\n"
840 "foo(), true")->BooleanValue());
841 }
842
843
844 THREADED_TEST(ExternalWrap) {
845 // Check heap allocated object.
846 int* ptr = new int;
847 expected_ptr = ptr;
848 TestExternalPointerWrapping();
849 delete ptr;
850
851 // Check stack allocated object.
852 int foo;
853 expected_ptr = &foo;
854 TestExternalPointerWrapping();
855
856 // Check not aligned addresses.
857 const int n = 100;
858 char* s = new char[n];
859 for (int i = 0; i < n; i++) {
860 expected_ptr = s + i;
861 TestExternalPointerWrapping();
862 }
863
864 delete[] s;
865
866 // Check several invalid addresses.
867 expected_ptr = reinterpret_cast<void*>(1);
868 TestExternalPointerWrapping();
869
870 expected_ptr = reinterpret_cast<void*>(0xdeadbeef);
871 TestExternalPointerWrapping();
872
873 expected_ptr = reinterpret_cast<void*>(0xdeadbeef + 1);
874 TestExternalPointerWrapping();
875
876 #if defined(V8_HOST_ARCH_X64)
877 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef);
878 TestExternalPointerWrapping();
879
880 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1);
881 TestExternalPointerWrapping();
882 #endif
883 }
884
885
817 THREADED_TEST(FindInstanceInPrototypeChain) { 886 THREADED_TEST(FindInstanceInPrototypeChain) {
818 v8::HandleScope scope; 887 v8::HandleScope scope;
819 LocalContext env; 888 LocalContext env;
820 889
821 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(); 890 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New();
822 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(); 891 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New();
823 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(); 892 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New();
824 derived->Inherit(base); 893 derived->Inherit(base);
825 894
826 Local<v8::Function> base_function = base->GetFunction(); 895 Local<v8::Function> base_function = base->GetFunction();
(...skipping 10965 matching lines...) Expand 10 before | Expand all | Expand 10 after
11792 v8::Context::Scope context_scope(context.local()); 11861 v8::Context::Scope context_scope(context.local());
11793 11862
11794 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 11863 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New();
11795 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 11864 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
11796 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 11865 context->Global()->Set(v8_str("o"), tmpl->NewInstance());
11797 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 11866 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
11798 "var result = []; for (var k in o) result.push(k); result")); 11867 "var result = []; for (var k in o) result.push(k); result"));
11799 CHECK_EQ(1, result->Length()); 11868 CHECK_EQ(1, result->Length());
11800 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); 11869 CHECK_EQ(v8_str("universalAnswer"), result->Get(0));
11801 } 11870 }
OLDNEW
« no previous file with comments | « src/version.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698