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

Unified Diff: test/cctest/test-api.cc

Issue 6119009: Wrap external pointers more carefully. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
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
« src/api.cc ('K') | « src/api.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
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 9539973693b10cb0fd5e0e5546c41e762737ba7a..a70eeec493a5480aa607bb3b7494778037cf38cf 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -814,6 +814,39 @@ THREADED_TEST(FunctionTemplate) {
}
+static v8::Handle<v8::Value> callback(const v8::Arguments& args) {
+ int* value = reinterpret_cast<int*>(v8::External::Unwrap(args.Data()));
+ CHECK_EQ(42, *value);
+ return v8::Integer::New(*value);
+}
+
+
+THREADED_TEST(PointerAsData) {
+ v8::HandleScope scope;
+ LocalContext env;
+
+ int* value = new int;
+ *value = 42;
+ v8::Handle<v8::Value> data = v8::External::Wrap(value);
+
+ 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++) {\n"
+ " if (42 != obj.func()) throw 'oops';\n"
+ " }\n"
+ " return true;\n"
+ "}\n"
+ "foo(), true")->BooleanValue());
+
+ delete value;
+}
+
+
THREADED_TEST(FindInstanceInPrototypeChain) {
v8::HandleScope scope;
LocalContext env;
« src/api.cc ('K') | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698