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 7572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7583 // global object (not the proxy), and make sure that the dictionary | 7583 // global object (not the proxy), and make sure that the dictionary |
7584 // load IC doesn't mess up loading directly from the global object. | 7584 // load IC doesn't mess up loading directly from the global object. |
7585 context->DetachGlobal(); | 7585 context->DetachGlobal(); |
7586 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); | 7586 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); |
7587 } | 7587 } |
7588 | 7588 |
7589 | 7589 |
7590 THREADED_TEST(PixelArray) { | 7590 THREADED_TEST(PixelArray) { |
7591 v8::HandleScope scope; | 7591 v8::HandleScope scope; |
7592 LocalContext context; | 7592 LocalContext context; |
7593 const int kElementCount = 40; | 7593 const int kElementCount = 260; |
7594 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); | 7594 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); |
7595 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(kElementCount, | 7595 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(kElementCount, |
7596 pixel_data); | 7596 pixel_data); |
7597 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. | 7597 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. |
7598 for (int i = 0; i < kElementCount; i++) { | 7598 for (int i = 0; i < kElementCount; i++) { |
7599 pixels->set(i, i); | 7599 pixels->set(i, i % 256); |
7600 } | 7600 } |
7601 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. | 7601 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. |
7602 for (int i = 0; i < kElementCount; i++) { | 7602 for (int i = 0; i < kElementCount; i++) { |
7603 CHECK_EQ(i, pixels->get(i)); | 7603 CHECK_EQ(i % 256, pixels->get(i)); |
7604 CHECK_EQ(i, pixel_data[i]); | 7604 CHECK_EQ(i % 256, pixel_data[i]); |
7605 } | 7605 } |
7606 | 7606 |
7607 v8::Handle<v8::Object> obj = v8::Object::New(); | 7607 v8::Handle<v8::Object> obj = v8::Object::New(); |
7608 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 7608 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
7609 // Set the elements to be the pixels. | 7609 // Set the elements to be the pixels. |
7610 // jsobj->set_elements(*pixels); | 7610 // jsobj->set_elements(*pixels); |
7611 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); | 7611 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); |
7612 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1))->value()); | 7612 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1))->value()); |
7613 obj->Set(v8_str("field"), v8::Int32::New(1503)); | 7613 obj->Set(v8_str("field"), v8::Int32::New(1503)); |
7614 context->Global()->Set(v8_str("pixels"), obj); | 7614 context->Global()->Set(v8_str("pixels"), obj); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7758 result = CompileRun("pixels[1] = 23;" | 7758 result = CompileRun("pixels[1] = 23;" |
7759 "pixels.__proto__ = [];" | 7759 "pixels.__proto__ = [];" |
7760 "js_array.__proto__ = pixels;" | 7760 "js_array.__proto__ = pixels;" |
7761 "js_array.concat(pixels);"); | 7761 "js_array.concat(pixels);"); |
7762 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); | 7762 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); |
7763 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); | 7763 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); |
7764 | 7764 |
7765 result = CompileRun("pixels[1] = 23;"); | 7765 result = CompileRun("pixels[1] = 23;"); |
7766 CHECK_EQ(23, result->Int32Value()); | 7766 CHECK_EQ(23, result->Int32Value()); |
7767 | 7767 |
7768 // Test for index greater than 255. Regression test for: | |
7769 // http://code.google.com/p/chromium/issues/detail?id=26337. | |
7770 result = CompileRun("pixels[256] = 255;"); | |
7771 CHECK_EQ(255, result->Int32Value()); | |
7772 result = CompileRun("var i = 0;" | |
7773 "for (var j = 0; j < 8; j++) { i = pixels[256]; }" | |
Søren Thygesen Gjesse
2009/11/18 11:30:16
How about using i+= pixels[256] and checking for i
Mads Ager (chromium)
2009/11/18 11:35:56
The 8 is only there to make sure that we hit the I
| |
7774 "i"); | |
7775 CHECK_EQ(255, result->Int32Value()); | |
7776 | |
7768 free(pixel_data); | 7777 free(pixel_data); |
7769 } | 7778 } |
7770 | 7779 |
7771 | 7780 |
7772 template <class ExternalArrayClass, class ElementType> | 7781 template <class ExternalArrayClass, class ElementType> |
7773 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, | 7782 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, |
7774 int64_t low, | 7783 int64_t low, |
7775 int64_t high) { | 7784 int64_t high) { |
7776 v8::HandleScope scope; | 7785 v8::HandleScope scope; |
7777 LocalContext context; | 7786 LocalContext context; |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8368 " i++;" | 8377 " i++;" |
8369 " return s(o);" | 8378 " return s(o);" |
8370 " }" | 8379 " }" |
8371 " }" | 8380 " }" |
8372 "};" | 8381 "};" |
8373 "s(o);"); | 8382 "s(o);"); |
8374 CHECK(try_catch.HasCaught()); | 8383 CHECK(try_catch.HasCaught()); |
8375 v8::String::Utf8Value value(try_catch.Exception()); | 8384 v8::String::Utf8Value value(try_catch.Exception()); |
8376 CHECK_EQ(0, strcmp(*value, "Hey!")); | 8385 CHECK_EQ(0, strcmp(*value, "Hey!")); |
8377 } | 8386 } |
OLD | NEW |