Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: test/cctest/test-api.cc

Issue 159263: - A prototype which allows to expose CanvasPixelArray functionality... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 7530 matching lines...) Expand 10 before | Expand all | Expand 10 after
7541 "var obj = { x: { foo: 42 }, y: 87 };\n" 7541 "var obj = { x: { foo: 42 }, y: 87 };\n"
7542 "var x = obj.x;\n" 7542 "var x = obj.x;\n"
7543 "delete obj.y;\n" 7543 "delete obj.y;\n"
7544 "for (var i = 0; i < 5; i++) f(obj);"); 7544 "for (var i = 0; i < 5; i++) f(obj);");
7545 // Detach the global object to make 'this' refer directly to the 7545 // Detach the global object to make 'this' refer directly to the
7546 // global object (not the proxy), and make sure that the dictionary 7546 // global object (not the proxy), and make sure that the dictionary
7547 // load IC doesn't mess up loading directly from the global object. 7547 // load IC doesn't mess up loading directly from the global object.
7548 context->DetachGlobal(); 7548 context->DetachGlobal();
7549 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); 7549 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value());
7550 } 7550 }
7551
7552
7553 THREADED_TEST(PixelArray) {
7554 v8::HandleScope scope;
7555 LocalContext context;
7556 const int kElementCount = 40;
7557 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
7558 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(kElementCount,
7559 pixel_data);
7560 i::Heap::CollectAllGarbage(); // Force GC to trigger verification.
7561 for (int i = 0; i < kElementCount; i++) {
7562 pixels->set(i, i);
7563 }
7564 i::Heap::CollectAllGarbage(); // Force GC to trigger verification.
7565 for (int i = 0; i < kElementCount; i++) {
7566 CHECK_EQ(i, pixels->get(i));
7567 CHECK_EQ(i, pixel_data[i]);
7568 }
7569
7570 v8::Handle<v8::Object> obj = v8::Object::New();
7571 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
7572 // Set the elements to be the pixels.
7573 // jsobj->set_elements(*pixels);
7574 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
7575 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1))->value());
7576 obj->Set(v8_str("field"), v8::Int32::New(1503));
7577 context->Global()->Set(v8_str("pixels"), obj);
7578 v8::Handle<v8::Value> result = CompileRun("pixels.field");
7579 CHECK_EQ(1503, result->Int32Value());
7580 result = CompileRun("pixels[1]");
7581 CHECK_EQ(1, result->Int32Value());
7582 result = CompileRun("var sum = 0;"
7583 "for (var i = 0; i < 8; i++) {"
7584 " sum += pixels[i];"
7585 "}"
7586 "sum;");
7587 CHECK_EQ(28, result->Int32Value());
7588
7589 i::Handle<i::Smi> value(i::Smi::FromInt(2));
7590 i::SetElement(jsobj, 1, value);
7591 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(1))->value());
7592 *value.location() = i::Smi::FromInt(256);
7593 i::SetElement(jsobj, 1, value);
7594 CHECK_EQ(255, i::Smi::cast(jsobj->GetElement(1))->value());
7595 *value.location() = i::Smi::FromInt(-1);
7596 i::SetElement(jsobj, 1, value);
7597 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1))->value());
7598
7599 result = CompileRun("for (var i = 0; i < 8; i++) {"
7600 " pixels[i] = (i * 65) - 109;"
7601 "}"
7602 "pixels[1] + pixels[6];");
7603 CHECK_EQ(255, result->Int32Value());
7604 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(0))->value());
7605 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1))->value());
7606 CHECK_EQ(21, i::Smi::cast(jsobj->GetElement(2))->value());
7607 CHECK_EQ(86, i::Smi::cast(jsobj->GetElement(3))->value());
7608 CHECK_EQ(151, i::Smi::cast(jsobj->GetElement(4))->value());
7609 CHECK_EQ(216, i::Smi::cast(jsobj->GetElement(5))->value());
7610 CHECK_EQ(255, i::Smi::cast(jsobj->GetElement(6))->value());
7611 CHECK_EQ(255, i::Smi::cast(jsobj->GetElement(7))->value());
7612 result = CompileRun("var sum = 0;"
7613 "for (var i = 0; i < 8; i++) {"
7614 " sum += pixels[i];"
7615 "}"
7616 "sum;");
7617 CHECK_EQ(984, result->Int32Value());
7618
7619 result = CompileRun("for (var i = 0; i < 8; i++) {"
7620 " pixels[i] = (i * 1.1);"
7621 "}"
7622 "pixels[1] + pixels[6];");
7623 CHECK_EQ(8, result->Int32Value());
7624 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(0))->value());
7625 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1))->value());
7626 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(2))->value());
7627 CHECK_EQ(3, i::Smi::cast(jsobj->GetElement(3))->value());
7628 CHECK_EQ(4, i::Smi::cast(jsobj->GetElement(4))->value());
7629 CHECK_EQ(6, i::Smi::cast(jsobj->GetElement(5))->value());
7630 CHECK_EQ(7, i::Smi::cast(jsobj->GetElement(6))->value());
7631 CHECK_EQ(8, i::Smi::cast(jsobj->GetElement(7))->value());
7632
7633 result = CompileRun("for (var i = 0; i < 8; i++) {"
7634 " pixels[7] = undefined;"
7635 "}"
7636 "pixels[7];");
7637 CHECK_EQ(0, result->Int32Value());
7638 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(7))->value());
7639
7640 result = CompileRun("for (var i = 0; i < 8; i++) {"
7641 " pixels[6] = '2.3';"
7642 "}"
7643 "pixels[6];");
7644 CHECK_EQ(2, result->Int32Value());
7645 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(6))->value());
7646
7647 result = CompileRun("var nan = 0/0;"
7648 "for (var i = 0; i < 8; i++) {"
7649 " pixels[5] = nan;"
7650 "}"
7651 "pixels[5];");
7652 CHECK_EQ(0, result->Int32Value());
7653 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(5))->value());
7654
7655 result = CompileRun("pixels[3] = 33;"
7656 "delete pixels[3];"
7657 "pixels[3];");
7658 CHECK_EQ(33, result->Int32Value());
7659
7660 result = CompileRun("pixels[0] = 10; pixels[1] = 11;"
7661 "pixels[2] = 12; pixels[3] = 13;"
7662 "pixels.__defineGetter__('2',"
7663 "function() { return 120; });"
7664 "pixels[2];");
7665 CHECK_EQ(12, result->Int32Value());
7666
7667 result = CompileRun("var js_array = new Array(40);"
7668 "js_array[0] = 77;"
7669 "js_array;"
7670 );
7671 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value());
7672
7673 result = CompileRun("pixels[1] = 23;"
7674 "pixels.__proto__ = [];"
7675 "js_array.__proto__ = pixels;"
7676 "js_array.concat(pixels);");
7677 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value());
7678 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value());
7679
7680 free(pixel_data);
7681 }
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698