OLD | NEW |
---|---|
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 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1397 char_ptr = reinterpret_cast<char*>(v8::External::Unwrap(one)); | 1397 char_ptr = reinterpret_cast<char*>(v8::External::Unwrap(one)); |
1398 CHECK_EQ('1', *char_ptr); | 1398 CHECK_EQ('1', *char_ptr); |
1399 char_ptr = reinterpret_cast<char*>(v8::External::Unwrap(two)); | 1399 char_ptr = reinterpret_cast<char*>(v8::External::Unwrap(two)); |
1400 CHECK_EQ('2', *char_ptr); | 1400 CHECK_EQ('2', *char_ptr); |
1401 char_ptr = reinterpret_cast<char*>(v8::External::Unwrap(three)); | 1401 char_ptr = reinterpret_cast<char*>(v8::External::Unwrap(three)); |
1402 CHECK_EQ('3', *char_ptr); | 1402 CHECK_EQ('3', *char_ptr); |
1403 i::DeleteArray(data); | 1403 i::DeleteArray(data); |
1404 } | 1404 } |
1405 | 1405 |
1406 | 1406 |
1407 THREADED_TEST(Blob) { | |
1408 v8::HandleScope scope; | |
1409 Local<v8::Blob> blob = v8::Blob::New(3); | |
1410 blob->SetByte(0, 10); | |
1411 blob->SetByte(1, 11); | |
1412 blob->SetByte(2, 12); | |
1413 LocalContext env; | |
1414 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
| |
1415 Local<Value> reblob_obj = Script::Compile(v8_str("this.blob"))->Run(); | |
1416 v8::Handle<v8::Blob> reblob = v8::Handle<v8::Blob>::Cast(reblob_obj); | |
1417 int count = reblob->ByteCount(); | |
1418 CHECK_EQ(3, count); | |
1419 | |
1420 uint8_t b = reblob->GetByte(0); | |
1421 CHECK_EQ(10, b); | |
1422 | |
1423 b = reblob->GetByte(1); | |
1424 CHECK_EQ(11, b); | |
1425 | |
1426 b = reblob->GetByte(2); | |
1427 CHECK_EQ(12, b); | |
1428 | |
1429 uint8_t *p = reblob->GetAddress(); | |
1430 CHECK_EQ(10, p[0]); | |
1431 CHECK_EQ(11, p[1]); | |
1432 CHECK_EQ(12, p[2]); | |
1433 | |
1434 p[2] = 52; | |
1435 b = reblob->GetByte(2); | |
1436 CHECK_EQ(52, b); | |
1437 } | |
1438 | |
1439 | |
1407 THREADED_TEST(GlobalHandle) { | 1440 THREADED_TEST(GlobalHandle) { |
1408 v8::Persistent<String> global; | 1441 v8::Persistent<String> global; |
1409 { | 1442 { |
1410 v8::HandleScope scope; | 1443 v8::HandleScope scope; |
1411 Local<String> str = v8_str("str"); | 1444 Local<String> str = v8_str("str"); |
1412 global = v8::Persistent<String>::New(str); | 1445 global = v8::Persistent<String>::New(str); |
1413 } | 1446 } |
1414 CHECK_EQ(global->Length(), 3); | 1447 CHECK_EQ(global->Length(), 3); |
1415 global.Dispose(); | 1448 global.Dispose(); |
1416 } | 1449 } |
(...skipping 6951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8368 " i++;" | 8401 " i++;" |
8369 " return s(o);" | 8402 " return s(o);" |
8370 " }" | 8403 " }" |
8371 " }" | 8404 " }" |
8372 "};" | 8405 "};" |
8373 "s(o);"); | 8406 "s(o);"); |
8374 CHECK(try_catch.HasCaught()); | 8407 CHECK(try_catch.HasCaught()); |
8375 v8::String::Utf8Value value(try_catch.Exception()); | 8408 v8::String::Utf8Value value(try_catch.Exception()); |
8376 CHECK_EQ(0, strcmp(*value, "Hey!")); | 8409 CHECK_EQ(0, strcmp(*value, "Hey!")); |
8377 } | 8410 } |
OLD | NEW |