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 10326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10337 | 10337 |
10338 // Test for index greater than 255. Regression test for: | 10338 // Test for index greater than 255. Regression test for: |
10339 // http://code.google.com/p/chromium/issues/detail?id=26337. | 10339 // http://code.google.com/p/chromium/issues/detail?id=26337. |
10340 result = CompileRun("pixels[256] = 255;"); | 10340 result = CompileRun("pixels[256] = 255;"); |
10341 CHECK_EQ(255, result->Int32Value()); | 10341 CHECK_EQ(255, result->Int32Value()); |
10342 result = CompileRun("var i = 0;" | 10342 result = CompileRun("var i = 0;" |
10343 "for (var j = 0; j < 8; j++) { i = pixels[256]; }" | 10343 "for (var j = 0; j < 8; j++) { i = pixels[256]; }" |
10344 "i"); | 10344 "i"); |
10345 CHECK_EQ(255, result->Int32Value()); | 10345 CHECK_EQ(255, result->Int32Value()); |
10346 | 10346 |
| 10347 // Make sure that pixel array ICs recognize when a non-pixel array |
| 10348 // is passed to it. |
| 10349 result = CompileRun("function pa_load(p) {" |
| 10350 " var sum = 0;" |
| 10351 " for (var j = 0; j < 256; j++) { sum += p[j]; }" |
| 10352 " return sum;" |
| 10353 "}" |
| 10354 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" |
| 10355 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }" |
| 10356 "just_ints = new Object();" |
| 10357 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" |
| 10358 "for (var i = 0; i < 10; ++i) {" |
| 10359 " result = pa_load(just_ints);" |
| 10360 "}" |
| 10361 "result"); |
| 10362 CHECK_EQ(32640, result->Int32Value()); |
| 10363 |
| 10364 // Make sure that pixel array ICs recognize out-of-bound accesses. |
| 10365 result = CompileRun("function pa_load(p, start) {" |
| 10366 " var sum = 0;" |
| 10367 " for (var j = start; j < 256; j++) { sum += p[j]; }" |
| 10368 " return sum;" |
| 10369 "}" |
| 10370 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" |
| 10371 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }" |
| 10372 "for (var i = 0; i < 10; ++i) {" |
| 10373 " result = pa_load(pixels,-10);" |
| 10374 "}" |
| 10375 "result"); |
| 10376 CHECK_EQ(0, result->Int32Value()); |
| 10377 |
| 10378 // Make sure that generic ICs properly handles a pixel array. |
| 10379 result = CompileRun("function pa_load(p) {" |
| 10380 " var sum = 0;" |
| 10381 " for (var j = 0; j < 256; j++) { sum += p[j]; }" |
| 10382 " return sum;" |
| 10383 "}" |
| 10384 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" |
| 10385 "just_ints = new Object();" |
| 10386 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" |
| 10387 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }" |
| 10388 "for (var i = 0; i < 10; ++i) {" |
| 10389 " result = pa_load(pixels);" |
| 10390 "}" |
| 10391 "result"); |
| 10392 CHECK_EQ(32640, result->Int32Value()); |
| 10393 |
| 10394 // Make sure that generic load ICs recognize out-of-bound accesses in |
| 10395 // pixel arrays. |
| 10396 result = CompileRun("function pa_load(p, start) {" |
| 10397 " var sum = 0;" |
| 10398 " for (var j = start; j < 256; j++) { sum += p[j]; }" |
| 10399 " return sum;" |
| 10400 "}" |
| 10401 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" |
| 10402 "just_ints = new Object();" |
| 10403 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" |
| 10404 "for (var i = 0; i < 10; ++i) { pa_load(just_ints,0); }" |
| 10405 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }" |
| 10406 "for (var i = 0; i < 10; ++i) {" |
| 10407 " result = pa_load(pixels,-10);" |
| 10408 "}" |
| 10409 "result"); |
| 10410 CHECK_EQ(0, result->Int32Value()); |
| 10411 |
| 10412 // Make sure that generic ICs properly handles other types than pixel |
| 10413 // arrays (that the inlined fast pixel array test leaves the right information |
| 10414 // in the right registers). |
| 10415 result = CompileRun("function pa_load(p) {" |
| 10416 " var sum = 0;" |
| 10417 " for (var j = 0; j < 256; j++) { sum += p[j]; }" |
| 10418 " return sum;" |
| 10419 "}" |
| 10420 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" |
| 10421 "just_ints = new Object();" |
| 10422 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" |
| 10423 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }" |
| 10424 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }" |
| 10425 "sparse_array = new Object();" |
| 10426 "for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }" |
| 10427 "sparse_array[1000000] = 3;" |
| 10428 "for (var i = 0; i < 10; ++i) {" |
| 10429 " result = pa_load(sparse_array);" |
| 10430 "}" |
| 10431 "result"); |
| 10432 CHECK_EQ(32640, result->Int32Value()); |
| 10433 |
10347 free(pixel_data); | 10434 free(pixel_data); |
10348 } | 10435 } |
10349 | 10436 |
10350 | 10437 |
10351 THREADED_TEST(PixelArrayInfo) { | 10438 THREADED_TEST(PixelArrayInfo) { |
10352 v8::HandleScope scope; | 10439 v8::HandleScope scope; |
10353 LocalContext context; | 10440 LocalContext context; |
10354 for (int size = 0; size < 100; size += 10) { | 10441 for (int size = 0; size < 100; size += 10) { |
10355 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); | 10442 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); |
10356 v8::Handle<v8::Object> obj = v8::Object::New(); | 10443 v8::Handle<v8::Object> obj = v8::Object::New(); |
(...skipping 1855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12212 v8::Context::Scope context_scope(context.local()); | 12299 v8::Context::Scope context_scope(context.local()); |
12213 | 12300 |
12214 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); | 12301 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); |
12215 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 12302 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); |
12216 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 12303 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
12217 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 12304 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
12218 "var result = []; for (var k in o) result.push(k); result")); | 12305 "var result = []; for (var k in o) result.push(k); result")); |
12219 CHECK_EQ(1, result->Length()); | 12306 CHECK_EQ(1, result->Length()); |
12220 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 12307 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
12221 } | 12308 } |
OLD | NEW |