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 10156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10167 v8::Handle<v8::Object> obj = v8::Object::New(); | 10167 v8::Handle<v8::Object> obj = v8::Object::New(); |
10168 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 10168 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
10169 // Set the elements to be the pixels. | 10169 // Set the elements to be the pixels. |
10170 // jsobj->set_elements(*pixels); | 10170 // jsobj->set_elements(*pixels); |
10171 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); | 10171 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); |
10172 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | 10172 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); |
10173 obj->Set(v8_str("field"), v8::Int32::New(1503)); | 10173 obj->Set(v8_str("field"), v8::Int32::New(1503)); |
10174 context->Global()->Set(v8_str("pixels"), obj); | 10174 context->Global()->Set(v8_str("pixels"), obj); |
10175 v8::Handle<v8::Value> result = CompileRun("pixels.field"); | 10175 v8::Handle<v8::Value> result = CompileRun("pixels.field"); |
10176 CHECK_EQ(1503, result->Int32Value()); | 10176 CHECK_EQ(1503, result->Int32Value()); |
10177 result = CompileRun("pixels[1]"); | 10177 // result = CompileRun("pixels[1]"); |
10178 CHECK_EQ(1, result->Int32Value()); | 10178 // CHECK_EQ(1, result->Int32Value()); |
danno
2011/01/28 10:35:36
i'll fix this, shouldn't be commented out.
Mads Ager (chromium)
2011/01/28 10:39:16
Thanks!
| |
10179 | 10179 |
10180 result = CompileRun("var sum = 0;" | 10180 result = CompileRun("var sum = 0;" |
10181 "for (var i = 0; i < 8; i++) {" | 10181 "for (var i = 0; i < 8; i++) {" |
10182 " sum += pixels[i] = pixels[i] = -i;" | 10182 " sum += pixels[i] = pixels[i] = -i;" |
10183 "}" | 10183 "}" |
10184 "sum;"); | 10184 "sum;"); |
10185 CHECK_EQ(-28, result->Int32Value()); | 10185 CHECK_EQ(-28, result->Int32Value()); |
10186 | 10186 |
10187 result = CompileRun("var sum = 0;" | 10187 result = CompileRun("var sum = 0;" |
10188 "for (var i = 0; i < 8; i++) {" | 10188 "for (var i = 0; i < 8; i++) {" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10335 | 10335 |
10336 // Test for index greater than 255. Regression test for: | 10336 // Test for index greater than 255. Regression test for: |
10337 // http://code.google.com/p/chromium/issues/detail?id=26337. | 10337 // http://code.google.com/p/chromium/issues/detail?id=26337. |
10338 result = CompileRun("pixels[256] = 255;"); | 10338 result = CompileRun("pixels[256] = 255;"); |
10339 CHECK_EQ(255, result->Int32Value()); | 10339 CHECK_EQ(255, result->Int32Value()); |
10340 result = CompileRun("var i = 0;" | 10340 result = CompileRun("var i = 0;" |
10341 "for (var j = 0; j < 8; j++) { i = pixels[256]; }" | 10341 "for (var j = 0; j < 8; j++) { i = pixels[256]; }" |
10342 "i"); | 10342 "i"); |
10343 CHECK_EQ(255, result->Int32Value()); | 10343 CHECK_EQ(255, result->Int32Value()); |
10344 | 10344 |
10345 // Make sure that pixel array ICs recognize when a non-pixel array | |
10346 // is passed to it. | |
10347 result = CompileRun("function pa_load(p) {" | |
10348 " var sum = 0;" | |
10349 " for (var j = 0; j < 256; j++) { sum += p[j]; }" | |
10350 " return sum;" | |
10351 "}" | |
10352 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" | |
10353 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }" | |
10354 "just_ints = new Object();" | |
10355 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" | |
10356 "for (var i = 0; i < 10; ++i) { result = pa_load(just_ints ); }" | |
danno
2011/01/28 10:35:36
I'll fix the 80 cols, too, here and below.
Mads Ager (chromium)
2011/01/28 10:39:16
Thanks.
| |
10357 "result"); | |
10358 CHECK_EQ(32640, result->Int32Value()); | |
10359 | |
10360 // Make sure that pixel array ICs recognize out-of-bound accesses. | |
10361 result = CompileRun("function pa_load(p, start) {" | |
10362 " var sum = 0;" | |
10363 " for (var j = start; j < 256; j++) { sum += p[j]; }" | |
10364 " return sum;" | |
10365 "}" | |
10366 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" | |
10367 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }" | |
10368 "for (var i = 0; i < 10; ++i) { result = pa_load(pixels,-1 0); }" | |
10369 "result"); | |
10370 CHECK_EQ(0, result->Int32Value()); | |
10371 | |
10372 // Make sure that generic ICs properly handles a pixel array. | |
10373 result = CompileRun("function pa_load(p) {" | |
10374 " var sum = 0;" | |
10375 " for (var j = 0; j < 256; j++) { sum += p[j]; }" | |
10376 " return sum;" | |
10377 "}" | |
10378 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" | |
10379 "just_ints = new Object();" | |
10380 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" | |
10381 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }" | |
10382 "for (var i = 0; i < 10; ++i) { result = pa_load(pixels); }" | |
10383 "result"); | |
10384 CHECK_EQ(32640, result->Int32Value()); | |
10385 | |
10386 // Make sure that generic load ICs recognize out-of-bound accesses in | |
10387 // pixel arrays. | |
10388 result = CompileRun("function pa_load(p, start) {" | |
10389 " var sum = 0;" | |
10390 " for (var j = start; j < 256; j++) { sum += p[j]; }" | |
10391 " return sum;" | |
10392 "}" | |
10393 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" | |
10394 "just_ints = new Object();" | |
10395 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" | |
10396 "for (var i = 0; i < 10; ++i) { pa_load(just_ints,0); }" | |
10397 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }" | |
10398 "for (var i = 0; i < 10; ++i) { result = pa_load(pixels,-1 0); }" | |
10399 "result"); | |
10400 CHECK_EQ(0, result->Int32Value()); | |
10401 | |
10402 // Make sure that generic ICs properly handles other types than pixel | |
10403 // arrays (that the inlined fast pixel array test leaves the right information | |
10404 // in the right registers). | |
10405 result = CompileRun("function pa_load(p) {" | |
10406 " var sum = 0;" | |
10407 " for (var j = 0; j < 256; j++) { sum += p[j]; }" | |
10408 " return sum;" | |
10409 "}" | |
10410 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" | |
10411 "just_ints = new Object();" | |
10412 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" | |
10413 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }" | |
10414 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }" | |
10415 "sparse_array = new Object();" | |
10416 "for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }" | |
10417 "sparse_array[1000000] = 3;" | |
10418 "for (var i = 0; i < 10; ++i) { result = pa_load(sparse_ar ray); }" | |
10419 "result"); | |
10420 CHECK_EQ(32640, result->Int32Value()); | |
10421 | |
10345 free(pixel_data); | 10422 free(pixel_data); |
10346 } | 10423 } |
10347 | 10424 |
10348 | 10425 |
10349 THREADED_TEST(PixelArrayInfo) { | 10426 THREADED_TEST(PixelArrayInfo) { |
10350 v8::HandleScope scope; | 10427 v8::HandleScope scope; |
10351 LocalContext context; | 10428 LocalContext context; |
10352 for (int size = 0; size < 100; size += 10) { | 10429 for (int size = 0; size < 100; size += 10) { |
10353 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); | 10430 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); |
10354 v8::Handle<v8::Object> obj = v8::Object::New(); | 10431 v8::Handle<v8::Object> obj = v8::Object::New(); |
(...skipping 1855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12210 v8::Context::Scope context_scope(context.local()); | 12287 v8::Context::Scope context_scope(context.local()); |
12211 | 12288 |
12212 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); | 12289 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); |
12213 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 12290 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); |
12214 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 12291 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
12215 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 12292 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
12216 "var result = []; for (var k in o) result.push(k); result")); | 12293 "var result = []; for (var k in o) result.push(k); result")); |
12217 CHECK_EQ(1, result->Length()); | 12294 CHECK_EQ(1, result->Length()); |
12218 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 12295 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
12219 } | 12296 } |
OLD | NEW |