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

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

Issue 391068: Add Blob API
Patch Set: Created 11 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 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 475cdf8b0db35e1cbf3e1284835908286bc370a6..4d8b3683d5a22adb10dc414cba6706866c664bb1 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1404,6 +1404,39 @@ THREADED_TEST(External) {
}
+THREADED_TEST(Blob) {
+ v8::HandleScope scope;
+ Local<v8::Blob> blob = v8::Blob::New(3);
+ blob->SetByte(0, 10);
+ blob->SetByte(1, 11);
+ blob->SetByte(2, 12);
+ LocalContext env;
+ env->Global()->Set(v8_str("blob"), blob);
Christian Plesner Hansen 2009/11/16 12:12:22 Like externals it is not safe to expose blobs dire
+ Local<Value> reblob_obj = Script::Compile(v8_str("this.blob"))->Run();
+ v8::Handle<v8::Blob> reblob = v8::Handle<v8::Blob>::Cast(reblob_obj);
+ int count = reblob->ByteCount();
+ CHECK_EQ(3, count);
+
+ uint8_t b = reblob->GetByte(0);
+ CHECK_EQ(10, b);
+
+ b = reblob->GetByte(1);
+ CHECK_EQ(11, b);
+
+ b = reblob->GetByte(2);
+ CHECK_EQ(12, b);
+
+ uint8_t *p = reblob->GetAddress();
+ CHECK_EQ(10, p[0]);
+ CHECK_EQ(11, p[1]);
+ CHECK_EQ(12, p[2]);
+
+ p[2] = 52;
+ b = reblob->GetByte(2);
+ CHECK_EQ(52, b);
+}
+
+
THREADED_TEST(GlobalHandle) {
v8::Persistent<String> global;
{
« 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