OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 int x = 3; | 1332 int x = 3; |
1333 Local<v8::External> ext = v8::External::New(&x); | 1333 Local<v8::External> ext = v8::External::New(&x); |
1334 LocalContext env; | 1334 LocalContext env; |
1335 env->Global()->Set(v8_str("ext"), ext); | 1335 env->Global()->Set(v8_str("ext"), ext); |
1336 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run(); | 1336 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run(); |
1337 v8::Handle<v8::External> reext = v8::Handle<v8::External>::Cast(reext_obj); | 1337 v8::Handle<v8::External> reext = v8::Handle<v8::External>::Cast(reext_obj); |
1338 int* ptr = static_cast<int*>(reext->Value()); | 1338 int* ptr = static_cast<int*>(reext->Value()); |
1339 CHECK_EQ(x, 3); | 1339 CHECK_EQ(x, 3); |
1340 *ptr = 10; | 1340 *ptr = 10; |
1341 CHECK_EQ(x, 10); | 1341 CHECK_EQ(x, 10); |
| 1342 |
| 1343 // Make sure unaligned pointers are wrapped properly. |
| 1344 char* data = "0123456789"; |
| 1345 Local<v8::External> zero = v8::External::New(&data[0]); |
| 1346 Local<v8::External> one = v8::External::New(&data[1]); |
| 1347 Local<v8::External> two = v8::External::New(&data[2]); |
| 1348 Local<v8::External> three = v8::External::New(&data[3]); |
| 1349 |
| 1350 char* char_ptr = reinterpret_cast<char*>(zero->Value()); |
| 1351 CHECK_EQ('0', *char_ptr); |
| 1352 char_ptr = reinterpret_cast<char*>(one->Value()); |
| 1353 CHECK_EQ('1', *char_ptr); |
| 1354 char_ptr = reinterpret_cast<char*>(two->Value()); |
| 1355 CHECK_EQ('2', *char_ptr); |
| 1356 char_ptr = reinterpret_cast<char*>(three->Value()); |
| 1357 CHECK_EQ('3', *char_ptr); |
1342 } | 1358 } |
1343 | 1359 |
1344 | 1360 |
1345 THREADED_TEST(GlobalHandle) { | 1361 THREADED_TEST(GlobalHandle) { |
1346 v8::Persistent<String> global; | 1362 v8::Persistent<String> global; |
1347 { | 1363 { |
1348 v8::HandleScope scope; | 1364 v8::HandleScope scope; |
1349 Local<String> str = v8_str("str"); | 1365 Local<String> str = v8_str("str"); |
1350 global = v8::Persistent<String>::New(str); | 1366 global = v8::Persistent<String>::New(str); |
1351 } | 1367 } |
(...skipping 4719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6071 | 6087 |
6072 // Local context should still be live. | 6088 // Local context should still be live. |
6073 CHECK(!local_env.IsEmpty()); | 6089 CHECK(!local_env.IsEmpty()); |
6074 local_env->Enter(); | 6090 local_env->Enter(); |
6075 | 6091 |
6076 // Should complete without problems. | 6092 // Should complete without problems. |
6077 RegExpStringModificationTest().RunTest(); | 6093 RegExpStringModificationTest().RunTest(); |
6078 | 6094 |
6079 local_env->Exit(); | 6095 local_env->Exit(); |
6080 } | 6096 } |
OLD | NEW |