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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/version.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
===================================================================
--- test/cctest/test-api.cc (revision 6311)
+++ test/cctest/test-api.cc (working copy)
@@ -814,6 +814,75 @@
}
+static void* expected_ptr;
+static v8::Handle<v8::Value> callback(const v8::Arguments& args) {
+ void* ptr = v8::External::Unwrap(args.Data());
+ CHECK_EQ(expected_ptr, ptr);
+ return v8::Boolean::New(true);
+}
+
+
+static void TestExternalPointerWrapping() {
+ v8::HandleScope scope;
+ LocalContext env;
+
+ v8::Handle<v8::Value> data = v8::External::Wrap(expected_ptr);
+
+ v8::Handle<v8::Object> obj = v8::Object::New();
+ obj->Set(v8_str("func"),
+ v8::FunctionTemplate::New(callback, data)->GetFunction());
+ env->Global()->Set(v8_str("obj"), obj);
+
+ CHECK(CompileRun(
+ "function foo() {\n"
+ " for (var i = 0; i < 13; i++) obj.func();\n"
+ "}\n"
+ "foo(), true")->BooleanValue());
+}
+
+
+THREADED_TEST(ExternalWrap) {
+ // Check heap allocated object.
+ int* ptr = new int;
+ expected_ptr = ptr;
+ TestExternalPointerWrapping();
+ delete ptr;
+
+ // Check stack allocated object.
+ int foo;
+ expected_ptr = &foo;
+ TestExternalPointerWrapping();
+
+ // Check not aligned addresses.
+ const int n = 100;
+ char* s = new char[n];
+ for (int i = 0; i < n; i++) {
+ expected_ptr = s + i;
+ TestExternalPointerWrapping();
+ }
+
+ delete[] s;
+
+ // Check several invalid addresses.
+ expected_ptr = reinterpret_cast<void*>(1);
+ TestExternalPointerWrapping();
+
+ expected_ptr = reinterpret_cast<void*>(0xdeadbeef);
+ TestExternalPointerWrapping();
+
+ expected_ptr = reinterpret_cast<void*>(0xdeadbeef + 1);
+ TestExternalPointerWrapping();
+
+#if defined(V8_HOST_ARCH_X64)
+ expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef);
+ TestExternalPointerWrapping();
+
+ expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1);
+ TestExternalPointerWrapping();
+#endif
+}
+
+
THREADED_TEST(FindInstanceInPrototypeChain) {
v8::HandleScope scope;
LocalContext env;
« 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