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

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

Issue 6241003: Port r6301 to 2.4 branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/2.4/
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 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 806
807 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); 807 Local<Value> result = v8_compile("(new obj()).toString()")->Run();
808 CHECK_EQ(v8_str("[object funky]"), result); 808 CHECK_EQ(v8_str("[object funky]"), result);
809 809
810 result = v8_compile("(new obj()).m")->Run(); 810 result = v8_compile("(new obj()).m")->Run();
811 CHECK_EQ(239, result->Int32Value()); 811 CHECK_EQ(239, result->Int32Value());
812 } 812 }
813 } 813 }
814 814
815 815
816 static void* expected_ptr;
817 static v8::Handle<v8::Value> callback(const v8::Arguments& args) {
818 void* ptr = v8::External::Unwrap(args.Data());
819 CHECK_EQ(expected_ptr, ptr);
820 return v8::Boolean::New(true);
821 }
822
823
824 static void TestExternalPointerWrapping() {
825 v8::HandleScope scope;
826 LocalContext env;
827
828 v8::Handle<v8::Value> data = v8::External::Wrap(expected_ptr);
829
830 v8::Handle<v8::Object> obj = v8::Object::New();
831 obj->Set(v8_str("func"),
832 v8::FunctionTemplate::New(callback, data)->GetFunction());
833 env->Global()->Set(v8_str("obj"), obj);
834
835 CHECK(CompileRun(
836 "function foo() {\n"
837 " for (var i = 0; i < 13; i++) obj.func();\n"
838 "}\n"
839 "foo(), true")->BooleanValue());
840 }
841
842
843 THREADED_TEST(ExternalWrap) {
844 // Check heap allocated object.
845 int* ptr = new int;
846 expected_ptr = ptr;
847 TestExternalPointerWrapping();
848 delete ptr;
849
850 // Check stack allocated object.
851 int foo;
852 expected_ptr = &foo;
853 TestExternalPointerWrapping();
854
855 // Check not aligned addresses.
856 const int n = 100;
857 char* s = new char[n];
858 for (int i = 0; i < n; i++) {
859 expected_ptr = s + i;
860 TestExternalPointerWrapping();
861 }
862
863 delete[] s;
864
865 // Check several invalid addresses.
866 expected_ptr = reinterpret_cast<void*>(1);
867 TestExternalPointerWrapping();
868
869 expected_ptr = reinterpret_cast<void*>(0xdeadbeef);
870 TestExternalPointerWrapping();
871
872 expected_ptr = reinterpret_cast<void*>(0xdeadbeef + 1);
873 TestExternalPointerWrapping();
874
875 #if defined(V8_HOST_ARCH_X64)
876 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef);
877 TestExternalPointerWrapping();
878
879 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1);
880 TestExternalPointerWrapping();
881 #endif
882 }
883
884
816 THREADED_TEST(FindInstanceInPrototypeChain) { 885 THREADED_TEST(FindInstanceInPrototypeChain) {
817 v8::HandleScope scope; 886 v8::HandleScope scope;
818 LocalContext env; 887 LocalContext env;
819 888
820 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(); 889 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New();
821 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(); 890 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New();
822 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(); 891 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New();
823 derived->Inherit(base); 892 derived->Inherit(base);
824 893
825 Local<v8::Function> base_function = base->GetFunction(); 894 Local<v8::Function> base_function = base->GetFunction();
(...skipping 10922 matching lines...) Expand 10 before | Expand all | Expand 10 after
11748 v8::Context::Scope context_scope(context.local()); 11817 v8::Context::Scope context_scope(context.local());
11749 11818
11750 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 11819 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New();
11751 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 11820 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
11752 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 11821 context->Global()->Set(v8_str("o"), tmpl->NewInstance());
11753 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 11822 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
11754 "var result = []; for (var k in o) result.push(k); result")); 11823 "var result = []; for (var k in o) result.push(k); result"));
11755 CHECK_EQ(1, result->Length()); 11824 CHECK_EQ(1, result->Length());
11756 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); 11825 CHECK_EQ(v8_str("universalAnswer"), result->Get(0));
11757 } 11826 }
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