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

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

Issue 1092923002: Remove support for externally backed elements from the API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « test/cctest/compiler/test-simplified-lowering.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 13489 matching lines...) Expand 10 before | Expand all | Expand 10 after
13500 static void CheckElementValue(i::Isolate* isolate, 13500 static void CheckElementValue(i::Isolate* isolate,
13501 int expected, 13501 int expected,
13502 i::Handle<i::Object> obj, 13502 i::Handle<i::Object> obj,
13503 int offset) { 13503 int offset) {
13504 i::Object* element = 13504 i::Object* element =
13505 *i::Object::GetElement(isolate, obj, offset).ToHandleChecked(); 13505 *i::Object::GetElement(isolate, obj, offset).ToHandleChecked();
13506 CHECK_EQ(expected, i::Smi::cast(element)->value()); 13506 CHECK_EQ(expected, i::Smi::cast(element)->value());
13507 } 13507 }
13508 13508
13509 13509
13510 THREADED_TEST(PixelArray) {
13511 LocalContext context;
13512 i::Isolate* isolate = CcTest::i_isolate();
13513 i::Factory* factory = isolate->factory();
13514 v8::HandleScope scope(context->GetIsolate());
13515 const int kElementCount = 260;
13516 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
13517 i::Handle<i::ExternalUint8ClampedArray> pixels =
13518 i::Handle<i::ExternalUint8ClampedArray>::cast(
13519 factory->NewExternalArray(kElementCount,
13520 v8::kExternalUint8ClampedArray,
13521 pixel_data));
13522 // Force GC to trigger verification.
13523 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
13524 for (int i = 0; i < kElementCount; i++) {
13525 pixels->set(i, i % 256);
13526 }
13527 // Force GC to trigger verification.
13528 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
13529 for (int i = 0; i < kElementCount; i++) {
13530 CHECK_EQ(i % 256, pixels->get_scalar(i));
13531 CHECK_EQ(i % 256, pixel_data[i]);
13532 }
13533
13534 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
13535 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
13536 // Set the elements to be the pixels.
13537 // jsobj->set_elements(*pixels);
13538 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
13539 CheckElementValue(isolate, 1, jsobj, 1);
13540 obj->Set(v8_str("field"), v8::Int32::New(CcTest::isolate(), 1503));
13541 context->Global()->Set(v8_str("pixels"), obj);
13542 v8::Handle<v8::Value> result = CompileRun("pixels.field");
13543 CHECK_EQ(1503, result->Int32Value());
13544 result = CompileRun("pixels[1]");
13545 CHECK_EQ(1, result->Int32Value());
13546
13547 result = CompileRun("var sum = 0;"
13548 "for (var i = 0; i < 8; i++) {"
13549 " sum += pixels[i] = pixels[i] = -i;"
13550 "}"
13551 "sum;");
13552 CHECK_EQ(-28, result->Int32Value());
13553
13554 result = CompileRun("var sum = 0;"
13555 "for (var i = 0; i < 8; i++) {"
13556 " sum += pixels[i] = pixels[i] = 0;"
13557 "}"
13558 "sum;");
13559 CHECK_EQ(0, result->Int32Value());
13560
13561 result = CompileRun("var sum = 0;"
13562 "for (var i = 0; i < 8; i++) {"
13563 " sum += pixels[i] = pixels[i] = 255;"
13564 "}"
13565 "sum;");
13566 CHECK_EQ(8 * 255, result->Int32Value());
13567
13568 result = CompileRun("var sum = 0;"
13569 "for (var i = 0; i < 8; i++) {"
13570 " sum += pixels[i] = pixels[i] = 256 + i;"
13571 "}"
13572 "sum;");
13573 CHECK_EQ(2076, result->Int32Value());
13574
13575 result = CompileRun("var sum = 0;"
13576 "for (var i = 0; i < 8; i++) {"
13577 " sum += pixels[i] = pixels[i] = i;"
13578 "}"
13579 "sum;");
13580 CHECK_EQ(28, result->Int32Value());
13581
13582 result = CompileRun("var sum = 0;"
13583 "for (var i = 0; i < 8; i++) {"
13584 " sum += pixels[i];"
13585 "}"
13586 "sum;");
13587 CHECK_EQ(28, result->Int32Value());
13588
13589 i::Handle<i::Smi> value(i::Smi::FromInt(2),
13590 reinterpret_cast<i::Isolate*>(context->GetIsolate()));
13591 i::Handle<i::Object> no_failure;
13592 no_failure = i::JSObject::SetElement(
13593 jsobj, 1, value, NONE, i::SLOPPY).ToHandleChecked();
13594 DCHECK(!no_failure.is_null());
13595 USE(no_failure);
13596 CheckElementValue(isolate, 2, jsobj, 1);
13597 *value.location() = i::Smi::FromInt(256);
13598 no_failure = i::JSObject::SetElement(
13599 jsobj, 1, value, NONE, i::SLOPPY).ToHandleChecked();
13600 DCHECK(!no_failure.is_null());
13601 USE(no_failure);
13602 CheckElementValue(isolate, 255, jsobj, 1);
13603 *value.location() = i::Smi::FromInt(-1);
13604 no_failure = i::JSObject::SetElement(
13605 jsobj, 1, value, NONE, i::SLOPPY).ToHandleChecked();
13606 DCHECK(!no_failure.is_null());
13607 USE(no_failure);
13608 CheckElementValue(isolate, 0, jsobj, 1);
13609
13610 result = CompileRun("for (var i = 0; i < 8; i++) {"
13611 " pixels[i] = (i * 65) - 109;"
13612 "}"
13613 "pixels[1] + pixels[6];");
13614 CHECK_EQ(255, result->Int32Value());
13615 CheckElementValue(isolate, 0, jsobj, 0);
13616 CheckElementValue(isolate, 0, jsobj, 1);
13617 CheckElementValue(isolate, 21, jsobj, 2);
13618 CheckElementValue(isolate, 86, jsobj, 3);
13619 CheckElementValue(isolate, 151, jsobj, 4);
13620 CheckElementValue(isolate, 216, jsobj, 5);
13621 CheckElementValue(isolate, 255, jsobj, 6);
13622 CheckElementValue(isolate, 255, jsobj, 7);
13623 result = CompileRun("var sum = 0;"
13624 "for (var i = 0; i < 8; i++) {"
13625 " sum += pixels[i];"
13626 "}"
13627 "sum;");
13628 CHECK_EQ(984, result->Int32Value());
13629
13630 result = CompileRun("for (var i = 0; i < 8; i++) {"
13631 " pixels[i] = (i * 1.1);"
13632 "}"
13633 "pixels[1] + pixels[6];");
13634 CHECK_EQ(8, result->Int32Value());
13635 CheckElementValue(isolate, 0, jsobj, 0);
13636 CheckElementValue(isolate, 1, jsobj, 1);
13637 CheckElementValue(isolate, 2, jsobj, 2);
13638 CheckElementValue(isolate, 3, jsobj, 3);
13639 CheckElementValue(isolate, 4, jsobj, 4);
13640 CheckElementValue(isolate, 6, jsobj, 5);
13641 CheckElementValue(isolate, 7, jsobj, 6);
13642 CheckElementValue(isolate, 8, jsobj, 7);
13643
13644 result = CompileRun("for (var i = 0; i < 8; i++) {"
13645 " pixels[7] = undefined;"
13646 "}"
13647 "pixels[7];");
13648 CHECK_EQ(0, result->Int32Value());
13649 CheckElementValue(isolate, 0, jsobj, 7);
13650
13651 result = CompileRun("for (var i = 0; i < 8; i++) {"
13652 " pixels[6] = '2.3';"
13653 "}"
13654 "pixels[6];");
13655 CHECK_EQ(2, result->Int32Value());
13656 CheckElementValue(isolate, 2, jsobj, 6);
13657
13658 result = CompileRun("for (var i = 0; i < 8; i++) {"
13659 " pixels[5] = NaN;"
13660 "}"
13661 "pixels[5];");
13662 CHECK_EQ(0, result->Int32Value());
13663 CheckElementValue(isolate, 0, jsobj, 5);
13664
13665 result = CompileRun("for (var i = 0; i < 8; i++) {"
13666 " pixels[8] = Infinity;"
13667 "}"
13668 "pixels[8];");
13669 CHECK_EQ(255, result->Int32Value());
13670 CheckElementValue(isolate, 255, jsobj, 8);
13671
13672 result = CompileRun("for (var i = 0; i < 8; i++) {"
13673 " pixels[9] = -Infinity;"
13674 "}"
13675 "pixels[9];");
13676 CHECK_EQ(0, result->Int32Value());
13677 CheckElementValue(isolate, 0, jsobj, 9);
13678
13679 result = CompileRun("pixels[3] = 33;"
13680 "delete pixels[3];"
13681 "pixels[3];");
13682 CHECK_EQ(33, result->Int32Value());
13683
13684 result = CompileRun("pixels[0] = 10; pixels[1] = 11;"
13685 "pixels[2] = 12; pixels[3] = 13;"
13686 "pixels.__defineGetter__('2',"
13687 "function() { return 120; });"
13688 "pixels[2];");
13689 CHECK_EQ(12, result->Int32Value());
13690
13691 result = CompileRun("var js_array = new Array(40);"
13692 "js_array[0] = 77;"
13693 "js_array;");
13694 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value());
13695
13696 result = CompileRun("pixels[1] = 23;"
13697 "pixels.__proto__ = [];"
13698 "js_array.__proto__ = pixels;"
13699 "js_array.concat(pixels);");
13700 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value());
13701 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value());
13702
13703 result = CompileRun("pixels[1] = 23;");
13704 CHECK_EQ(23, result->Int32Value());
13705
13706 // Test for index greater than 255. Regression test for:
13707 // http://code.google.com/p/chromium/issues/detail?id=26337.
13708 result = CompileRun("pixels[256] = 255;");
13709 CHECK_EQ(255, result->Int32Value());
13710 result = CompileRun("var i = 0;"
13711 "for (var j = 0; j < 8; j++) { i = pixels[256]; }"
13712 "i");
13713 CHECK_EQ(255, result->Int32Value());
13714
13715 // Make sure that pixel array ICs recognize when a non-pixel array
13716 // is passed to it.
13717 result = CompileRun("function pa_load(p) {"
13718 " var sum = 0;"
13719 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
13720 " return sum;"
13721 "}"
13722 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13723 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
13724 "just_ints = new Object();"
13725 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
13726 "for (var i = 0; i < 10; ++i) {"
13727 " result = pa_load(just_ints);"
13728 "}"
13729 "result");
13730 CHECK_EQ(32640, result->Int32Value());
13731
13732 // Make sure that pixel array ICs recognize out-of-bound accesses.
13733 result = CompileRun("function pa_load(p, start) {"
13734 " var sum = 0;"
13735 " for (var j = start; j < 256; j++) { sum += p[j]; }"
13736 " return sum;"
13737 "}"
13738 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13739 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
13740 "for (var i = 0; i < 10; ++i) {"
13741 " result = pa_load(pixels,-10);"
13742 "}"
13743 "result");
13744 CHECK_EQ(0, result->Int32Value());
13745
13746 // Make sure that generic ICs properly handles a pixel array.
13747 result = CompileRun("function pa_load(p) {"
13748 " var sum = 0;"
13749 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
13750 " return sum;"
13751 "}"
13752 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13753 "just_ints = new Object();"
13754 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
13755 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
13756 "for (var i = 0; i < 10; ++i) {"
13757 " result = pa_load(pixels);"
13758 "}"
13759 "result");
13760 CHECK_EQ(32640, result->Int32Value());
13761
13762 // Make sure that generic load ICs recognize out-of-bound accesses in
13763 // pixel arrays.
13764 result = CompileRun("function pa_load(p, start) {"
13765 " var sum = 0;"
13766 " for (var j = start; j < 256; j++) { sum += p[j]; }"
13767 " return sum;"
13768 "}"
13769 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13770 "just_ints = new Object();"
13771 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
13772 "for (var i = 0; i < 10; ++i) { pa_load(just_ints,0); }"
13773 "for (var i = 0; i < 10; ++i) { pa_load(pixels,0); }"
13774 "for (var i = 0; i < 10; ++i) {"
13775 " result = pa_load(pixels,-10);"
13776 "}"
13777 "result");
13778 CHECK_EQ(0, result->Int32Value());
13779
13780 // Make sure that generic ICs properly handles other types than pixel
13781 // arrays (that the inlined fast pixel array test leaves the right information
13782 // in the right registers).
13783 result = CompileRun("function pa_load(p) {"
13784 " var sum = 0;"
13785 " for (var j = 0; j < 256; j++) { sum += p[j]; }"
13786 " return sum;"
13787 "}"
13788 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13789 "just_ints = new Object();"
13790 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
13791 "for (var i = 0; i < 10; ++i) { pa_load(just_ints); }"
13792 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }"
13793 "sparse_array = new Object();"
13794 "for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }"
13795 "sparse_array[1000000] = 3;"
13796 "for (var i = 0; i < 10; ++i) {"
13797 " result = pa_load(sparse_array);"
13798 "}"
13799 "result");
13800 CHECK_EQ(32640, result->Int32Value());
13801
13802 // Make sure that pixel array store ICs clamp values correctly.
13803 result = CompileRun("function pa_store(p) {"
13804 " for (var j = 0; j < 256; j++) { p[j] = j * 2; }"
13805 "}"
13806 "pa_store(pixels);"
13807 "var sum = 0;"
13808 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
13809 "sum");
13810 CHECK_EQ(48896, result->Int32Value());
13811
13812 // Make sure that pixel array stores correctly handle accesses outside
13813 // of the pixel array..
13814 result = CompileRun("function pa_store(p,start) {"
13815 " for (var j = 0; j < 256; j++) {"
13816 " p[j+start] = j * 2;"
13817 " }"
13818 "}"
13819 "pa_store(pixels,0);"
13820 "pa_store(pixels,-128);"
13821 "var sum = 0;"
13822 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
13823 "sum");
13824 CHECK_EQ(65280, result->Int32Value());
13825
13826 // Make sure that the generic store stub correctly handle accesses outside
13827 // of the pixel array..
13828 result = CompileRun("function pa_store(p,start) {"
13829 " for (var j = 0; j < 256; j++) {"
13830 " p[j+start] = j * 2;"
13831 " }"
13832 "}"
13833 "pa_store(pixels,0);"
13834 "just_ints = new Object();"
13835 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }"
13836 "pa_store(just_ints, 0);"
13837 "pa_store(pixels,-128);"
13838 "var sum = 0;"
13839 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
13840 "sum");
13841 CHECK_EQ(65280, result->Int32Value());
13842
13843 // Make sure that the generic keyed store stub clamps pixel array values
13844 // correctly.
13845 result = CompileRun("function pa_store(p) {"
13846 " for (var j = 0; j < 256; j++) { p[j] = j * 2; }"
13847 "}"
13848 "pa_store(pixels);"
13849 "just_ints = new Object();"
13850 "pa_store(just_ints);"
13851 "pa_store(pixels);"
13852 "var sum = 0;"
13853 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }"
13854 "sum");
13855 CHECK_EQ(48896, result->Int32Value());
13856
13857 // Make sure that pixel array loads are optimized by crankshaft.
13858 result = CompileRun("function pa_load(p) {"
13859 " var sum = 0;"
13860 " for (var i=0; i<256; ++i) {"
13861 " sum += p[i];"
13862 " }"
13863 " return sum; "
13864 "}"
13865 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
13866 "for (var i = 0; i < 5000; ++i) {"
13867 " result = pa_load(pixels);"
13868 "}"
13869 "result");
13870 CHECK_EQ(32640, result->Int32Value());
13871
13872 // Make sure that pixel array stores are optimized by crankshaft.
13873 result = CompileRun("function pa_init(p) {"
13874 "for (var i = 0; i < 256; ++i) { p[i] = i; }"
13875 "}"
13876 "function pa_load(p) {"
13877 " var sum = 0;"
13878 " for (var i=0; i<256; ++i) {"
13879 " sum += p[i];"
13880 " }"
13881 " return sum; "
13882 "}"
13883 "for (var i = 0; i < 5000; ++i) {"
13884 " pa_init(pixels);"
13885 "}"
13886 "result = pa_load(pixels);"
13887 "result");
13888 CHECK_EQ(32640, result->Int32Value());
13889
13890 free(pixel_data);
13891 }
13892
13893
13894 THREADED_TEST(PixelArrayInfo) {
13895 LocalContext context;
13896 v8::HandleScope scope(context->GetIsolate());
13897 for (int size = 0; size < 100; size += 10) {
13898 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size));
13899 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
13900 obj->SetIndexedPropertiesToPixelData(pixel_data, size);
13901 CHECK(obj->HasIndexedPropertiesInPixelData());
13902 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData());
13903 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength());
13904 free(pixel_data);
13905 }
13906 }
13907
13908
13909 static void NotHandledIndexedPropertyGetter(
13910 uint32_t index,
13911 const v8::PropertyCallbackInfo<v8::Value>& info) {
13912 ApiTestFuzzer::Fuzz();
13913 }
13914
13915
13916 static void NotHandledIndexedPropertySetter(
13917 uint32_t index,
13918 Local<Value> value,
13919 const v8::PropertyCallbackInfo<v8::Value>& info) {
13920 ApiTestFuzzer::Fuzz();
13921 }
13922
13923
13924 THREADED_TEST(PixelArrayWithInterceptor) {
13925 LocalContext context;
13926 i::Factory* factory = CcTest::i_isolate()->factory();
13927 v8::Isolate* isolate = context->GetIsolate();
13928 v8::HandleScope scope(isolate);
13929 const int kElementCount = 260;
13930 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
13931 i::Handle<i::ExternalUint8ClampedArray> pixels =
13932 i::Handle<i::ExternalUint8ClampedArray>::cast(
13933 factory->NewExternalArray(kElementCount,
13934 v8::kExternalUint8ClampedArray,
13935 pixel_data));
13936 for (int i = 0; i < kElementCount; i++) {
13937 pixels->set(i, i % 256);
13938 }
13939 v8::Handle<v8::ObjectTemplate> templ =
13940 v8::ObjectTemplate::New(context->GetIsolate());
13941 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration(
13942 NotHandledIndexedPropertyGetter, NotHandledIndexedPropertySetter));
13943 v8::Handle<v8::Object> obj = templ->NewInstance();
13944 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
13945 context->Global()->Set(v8_str("pixels"), obj);
13946 v8::Handle<v8::Value> result = CompileRun("pixels[1]");
13947 CHECK_EQ(1, result->Int32Value());
13948 result = CompileRun("var sum = 0;"
13949 "for (var i = 0; i < 8; i++) {"
13950 " sum += pixels[i] = pixels[i] = -i;"
13951 "}"
13952 "sum;");
13953 CHECK_EQ(-28, result->Int32Value());
13954 result = CompileRun("pixels.hasOwnProperty('1')");
13955 CHECK(result->BooleanValue());
13956 free(pixel_data);
13957 }
13958
13959
13960 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) {
13961 switch (array_type) {
13962 case v8::kExternalInt8Array:
13963 case v8::kExternalUint8Array:
13964 case v8::kExternalUint8ClampedArray:
13965 return 1;
13966 break;
13967 case v8::kExternalInt16Array:
13968 case v8::kExternalUint16Array:
13969 return 2;
13970 break;
13971 case v8::kExternalInt32Array:
13972 case v8::kExternalUint32Array:
13973 case v8::kExternalFloat32Array:
13974 return 4;
13975 break;
13976 case v8::kExternalFloat64Array:
13977 return 8;
13978 break;
13979 default:
13980 UNREACHABLE();
13981 return -1;
13982 }
13983 UNREACHABLE();
13984 return -1;
13985 }
13986
13987
13988 template <class ExternalArrayClass, class ElementType> 13510 template <class ExternalArrayClass, class ElementType>
13989 static void ObjectWithExternalArrayTestHelper( 13511 static void ObjectWithExternalArrayTestHelper(Handle<Context> context,
13990 Handle<Context> context, 13512 v8::Handle<Object> obj,
13991 v8::Handle<Object> obj, 13513 int element_count,
13992 int element_count, 13514 i::ExternalArrayType array_type,
13993 v8::ExternalArrayType array_type, 13515 int64_t low, int64_t high) {
13994 int64_t low, int64_t high) {
13995 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); 13516 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
13996 i::Isolate* isolate = jsobj->GetIsolate(); 13517 i::Isolate* isolate = jsobj->GetIsolate();
13997 obj->Set(v8_str("field"), 13518 obj->Set(v8_str("field"),
13998 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503)); 13519 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503));
13999 context->Global()->Set(v8_str("ext_array"), obj); 13520 context->Global()->Set(v8_str("ext_array"), obj);
14000 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); 13521 v8::Handle<v8::Value> result = CompileRun("ext_array.field");
14001 CHECK_EQ(1503, result->Int32Value()); 13522 CHECK_EQ(1503, result->Int32Value());
14002 result = CompileRun("ext_array[1]"); 13523 result = CompileRun("ext_array[1]");
14003 CHECK_EQ(1, result->Int32Value()); 13524 CHECK_EQ(1, result->Int32Value());
14004 13525
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
14128 element_count); 13649 element_count);
14129 result = CompileRun(test_buf.start()); 13650 result = CompileRun(test_buf.start());
14130 CHECK_EQ(false, result->BooleanValue()); 13651 CHECK_EQ(false, result->BooleanValue());
14131 13652
14132 // Check other boundary conditions, values and operations. 13653 // Check other boundary conditions, values and operations.
14133 result = CompileRun("for (var i = 0; i < 8; i++) {" 13654 result = CompileRun("for (var i = 0; i < 8; i++) {"
14134 " ext_array[7] = undefined;" 13655 " ext_array[7] = undefined;"
14135 "}" 13656 "}"
14136 "ext_array[7];"); 13657 "ext_array[7];");
14137 CHECK_EQ(0, result->Int32Value()); 13658 CHECK_EQ(0, result->Int32Value());
14138 if (array_type == v8::kExternalFloat64Array || 13659 if (array_type == i::kExternalFloat64Array ||
14139 array_type == v8::kExternalFloat32Array) { 13660 array_type == i::kExternalFloat32Array) {
14140 CHECK(std::isnan( 13661 CHECK(std::isnan(
14141 i::Object::GetElement(isolate, jsobj, 7).ToHandleChecked()->Number())); 13662 i::Object::GetElement(isolate, jsobj, 7).ToHandleChecked()->Number()));
14142 } else { 13663 } else {
14143 CheckElementValue(isolate, 0, jsobj, 7); 13664 CheckElementValue(isolate, 0, jsobj, 7);
14144 } 13665 }
14145 13666
14146 result = CompileRun("for (var i = 0; i < 8; i++) {" 13667 result = CompileRun("for (var i = 0; i < 8; i++) {"
14147 " ext_array[6] = '2.3';" 13668 " ext_array[6] = '2.3';"
14148 "}" 13669 "}"
14149 "ext_array[6];"); 13670 "ext_array[6];");
14150 CHECK_EQ(2, result->Int32Value()); 13671 CHECK_EQ(2, result->Int32Value());
14151 CHECK_EQ(2, 13672 CHECK_EQ(2,
14152 static_cast<int>( 13673 static_cast<int>(
14153 i::Object::GetElement( 13674 i::Object::GetElement(
14154 isolate, jsobj, 6).ToHandleChecked()->Number())); 13675 isolate, jsobj, 6).ToHandleChecked()->Number()));
14155 13676
14156 if (array_type != v8::kExternalFloat32Array && 13677 if (array_type != i::kExternalFloat32Array &&
14157 array_type != v8::kExternalFloat64Array) { 13678 array_type != i::kExternalFloat64Array) {
14158 // Though the specification doesn't state it, be explicit about 13679 // Though the specification doesn't state it, be explicit about
14159 // converting NaNs and +/-Infinity to zero. 13680 // converting NaNs and +/-Infinity to zero.
14160 result = CompileRun("for (var i = 0; i < 8; i++) {" 13681 result = CompileRun("for (var i = 0; i < 8; i++) {"
14161 " ext_array[i] = 5;" 13682 " ext_array[i] = 5;"
14162 "}" 13683 "}"
14163 "for (var i = 0; i < 8; i++) {" 13684 "for (var i = 0; i < 8; i++) {"
14164 " ext_array[i] = NaN;" 13685 " ext_array[i] = NaN;"
14165 "}" 13686 "}"
14166 "ext_array[5];"); 13687 "ext_array[5];");
14167 CHECK_EQ(0, result->Int32Value()); 13688 CHECK_EQ(0, result->Int32Value());
14168 CheckElementValue(isolate, 0, jsobj, 5); 13689 CheckElementValue(isolate, 0, jsobj, 5);
14169 13690
14170 result = CompileRun("for (var i = 0; i < 8; i++) {" 13691 result = CompileRun("for (var i = 0; i < 8; i++) {"
14171 " ext_array[i] = 5;" 13692 " ext_array[i] = 5;"
14172 "}" 13693 "}"
14173 "for (var i = 0; i < 8; i++) {" 13694 "for (var i = 0; i < 8; i++) {"
14174 " ext_array[i] = Infinity;" 13695 " ext_array[i] = Infinity;"
14175 "}" 13696 "}"
14176 "ext_array[5];"); 13697 "ext_array[5];");
14177 int expected_value = 13698 int expected_value =
14178 (array_type == v8::kExternalUint8ClampedArray) ? 255 : 0; 13699 (array_type == i::kExternalUint8ClampedArray) ? 255 : 0;
14179 CHECK_EQ(expected_value, result->Int32Value()); 13700 CHECK_EQ(expected_value, result->Int32Value());
14180 CheckElementValue(isolate, expected_value, jsobj, 5); 13701 CheckElementValue(isolate, expected_value, jsobj, 5);
14181 13702
14182 result = CompileRun("for (var i = 0; i < 8; i++) {" 13703 result = CompileRun("for (var i = 0; i < 8; i++) {"
14183 " ext_array[i] = 5;" 13704 " ext_array[i] = 5;"
14184 "}" 13705 "}"
14185 "for (var i = 0; i < 8; i++) {" 13706 "for (var i = 0; i < 8; i++) {"
14186 " ext_array[i] = -Infinity;" 13707 " ext_array[i] = -Infinity;"
14187 "}" 13708 "}"
14188 "ext_array[5];"); 13709 "ext_array[5];");
14189 CHECK_EQ(0, result->Int32Value()); 13710 CHECK_EQ(0, result->Int32Value());
14190 CheckElementValue(isolate, 0, jsobj, 5); 13711 CheckElementValue(isolate, 0, jsobj, 5);
14191 13712
14192 // Check truncation behavior of integral arrays. 13713 // Check truncation behavior of integral arrays.
14193 const char* unsigned_data = 13714 const char* unsigned_data =
14194 "var source_data = [0.6, 10.6];" 13715 "var source_data = [0.6, 10.6];"
14195 "var expected_results = [0, 10];"; 13716 "var expected_results = [0, 10];";
14196 const char* signed_data = 13717 const char* signed_data =
14197 "var source_data = [0.6, 10.6, -0.6, -10.6];" 13718 "var source_data = [0.6, 10.6, -0.6, -10.6];"
14198 "var expected_results = [0, 10, 0, -10];"; 13719 "var expected_results = [0, 10, 0, -10];";
14199 const char* pixel_data = 13720 const char* pixel_data =
14200 "var source_data = [0.6, 10.6];" 13721 "var source_data = [0.6, 10.6];"
14201 "var expected_results = [1, 11];"; 13722 "var expected_results = [1, 11];";
14202 bool is_unsigned = 13723 bool is_unsigned = (array_type == i::kExternalUint8Array ||
14203 (array_type == v8::kExternalUint8Array || 13724 array_type == i::kExternalUint16Array ||
14204 array_type == v8::kExternalUint16Array || 13725 array_type == i::kExternalUint32Array);
14205 array_type == v8::kExternalUint32Array); 13726 bool is_pixel_data = array_type == i::kExternalUint8ClampedArray;
14206 bool is_pixel_data = array_type == v8::kExternalUint8ClampedArray;
14207 13727
14208 i::SNPrintF(test_buf, 13728 i::SNPrintF(test_buf,
14209 "%s" 13729 "%s"
14210 "var all_passed = true;" 13730 "var all_passed = true;"
14211 "for (var i = 0; i < source_data.length; i++) {" 13731 "for (var i = 0; i < source_data.length; i++) {"
14212 " for (var j = 0; j < 8; j++) {" 13732 " for (var j = 0; j < 8; j++) {"
14213 " ext_array[j] = source_data[i];" 13733 " ext_array[j] = source_data[i];"
14214 " }" 13734 " }"
14215 " all_passed = all_passed &&" 13735 " all_passed = all_passed &&"
14216 " (ext_array[5] == expected_results[i]);" 13736 " (ext_array[5] == expected_results[i]);"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
14281 "js_array.__proto__ = ext_array;" 13801 "js_array.__proto__ = ext_array;"
14282 "js_array.concat(ext_array);"); 13802 "js_array.concat(ext_array);");
14283 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); 13803 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value());
14284 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); 13804 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value());
14285 13805
14286 result = CompileRun("ext_array[1] = 23;"); 13806 result = CompileRun("ext_array[1] = 23;");
14287 CHECK_EQ(23, result->Int32Value()); 13807 CHECK_EQ(23, result->Int32Value());
14288 } 13808 }
14289 13809
14290 13810
14291 template <class FixedTypedArrayClass, 13811 template <class FixedTypedArrayClass, i::ElementsKind elements_kind,
14292 i::ElementsKind elements_kind,
14293 class ElementType> 13812 class ElementType>
14294 static void FixedTypedArrayTestHelper( 13813 static void FixedTypedArrayTestHelper(i::ExternalArrayType array_type,
14295 v8::ExternalArrayType array_type, 13814 ElementType low, ElementType high) {
14296 ElementType low,
14297 ElementType high) {
14298 i::FLAG_allow_natives_syntax = true; 13815 i::FLAG_allow_natives_syntax = true;
14299 LocalContext context; 13816 LocalContext context;
14300 i::Isolate* isolate = CcTest::i_isolate(); 13817 i::Isolate* isolate = CcTest::i_isolate();
14301 i::Factory* factory = isolate->factory(); 13818 i::Factory* factory = isolate->factory();
14302 v8::HandleScope scope(context->GetIsolate()); 13819 v8::HandleScope scope(context->GetIsolate());
14303 const int kElementCount = 260; 13820 const int kElementCount = 260;
14304 i::Handle<FixedTypedArrayClass> fixed_array = 13821 i::Handle<FixedTypedArrayClass> fixed_array =
14305 i::Handle<FixedTypedArrayClass>::cast( 13822 i::Handle<FixedTypedArrayClass>::cast(
14306 factory->NewFixedTypedArray(kElementCount, array_type)); 13823 factory->NewFixedTypedArray(kElementCount, array_type));
14307 CHECK_EQ(FixedTypedArrayClass::kInstanceType, 13824 CHECK_EQ(FixedTypedArrayClass::kInstanceType,
(...skipping 18 matching lines...) Expand all
14326 13843
14327 ObjectWithExternalArrayTestHelper<FixedTypedArrayClass, ElementType>( 13844 ObjectWithExternalArrayTestHelper<FixedTypedArrayClass, ElementType>(
14328 context.local(), obj, kElementCount, array_type, 13845 context.local(), obj, kElementCount, array_type,
14329 static_cast<int64_t>(low), 13846 static_cast<int64_t>(low),
14330 static_cast<int64_t>(high)); 13847 static_cast<int64_t>(high));
14331 } 13848 }
14332 13849
14333 13850
14334 THREADED_TEST(FixedUint8Array) { 13851 THREADED_TEST(FixedUint8Array) {
14335 FixedTypedArrayTestHelper<i::FixedUint8Array, i::UINT8_ELEMENTS, uint8_t>( 13852 FixedTypedArrayTestHelper<i::FixedUint8Array, i::UINT8_ELEMENTS, uint8_t>(
14336 v8::kExternalUint8Array, 13853 i::kExternalUint8Array, 0x0, 0xFF);
14337 0x0, 0xFF);
14338 } 13854 }
14339 13855
14340 13856
14341 THREADED_TEST(FixedUint8ClampedArray) { 13857 THREADED_TEST(FixedUint8ClampedArray) {
14342 FixedTypedArrayTestHelper<i::FixedUint8ClampedArray, 13858 FixedTypedArrayTestHelper<i::FixedUint8ClampedArray,
14343 i::UINT8_CLAMPED_ELEMENTS, uint8_t>( 13859 i::UINT8_CLAMPED_ELEMENTS, uint8_t>(
14344 v8::kExternalUint8ClampedArray, 13860 i::kExternalUint8ClampedArray, 0x0, 0xFF);
14345 0x0, 0xFF);
14346 } 13861 }
14347 13862
14348 13863
14349 THREADED_TEST(FixedInt8Array) { 13864 THREADED_TEST(FixedInt8Array) {
14350 FixedTypedArrayTestHelper<i::FixedInt8Array, i::INT8_ELEMENTS, int8_t>( 13865 FixedTypedArrayTestHelper<i::FixedInt8Array, i::INT8_ELEMENTS, int8_t>(
14351 v8::kExternalInt8Array, 13866 i::kExternalInt8Array, -0x80, 0x7F);
14352 -0x80, 0x7F);
14353 } 13867 }
14354 13868
14355 13869
14356 THREADED_TEST(FixedUint16Array) { 13870 THREADED_TEST(FixedUint16Array) {
14357 FixedTypedArrayTestHelper<i::FixedUint16Array, i::UINT16_ELEMENTS, uint16_t>( 13871 FixedTypedArrayTestHelper<i::FixedUint16Array, i::UINT16_ELEMENTS, uint16_t>(
14358 v8::kExternalUint16Array, 13872 i::kExternalUint16Array, 0x0, 0xFFFF);
14359 0x0, 0xFFFF);
14360 } 13873 }
14361 13874
14362 13875
14363 THREADED_TEST(FixedInt16Array) { 13876 THREADED_TEST(FixedInt16Array) {
14364 FixedTypedArrayTestHelper<i::FixedInt16Array, i::INT16_ELEMENTS, int16_t>( 13877 FixedTypedArrayTestHelper<i::FixedInt16Array, i::INT16_ELEMENTS, int16_t>(
14365 v8::kExternalInt16Array, 13878 i::kExternalInt16Array, -0x8000, 0x7FFF);
14366 -0x8000, 0x7FFF);
14367 } 13879 }
14368 13880
14369 13881
14370 THREADED_TEST(FixedUint32Array) { 13882 THREADED_TEST(FixedUint32Array) {
14371 FixedTypedArrayTestHelper<i::FixedUint32Array, i::UINT32_ELEMENTS, uint32_t>( 13883 FixedTypedArrayTestHelper<i::FixedUint32Array, i::UINT32_ELEMENTS, uint32_t>(
14372 v8::kExternalUint32Array, 13884 i::kExternalUint32Array, 0x0, UINT_MAX);
14373 0x0, UINT_MAX);
14374 } 13885 }
14375 13886
14376 13887
14377 THREADED_TEST(FixedInt32Array) { 13888 THREADED_TEST(FixedInt32Array) {
14378 FixedTypedArrayTestHelper<i::FixedInt32Array, i::INT32_ELEMENTS, int32_t>( 13889 FixedTypedArrayTestHelper<i::FixedInt32Array, i::INT32_ELEMENTS, int32_t>(
14379 v8::kExternalInt32Array, 13890 i::kExternalInt32Array, INT_MIN, INT_MAX);
14380 INT_MIN, INT_MAX);
14381 } 13891 }
14382 13892
14383 13893
14384 THREADED_TEST(FixedFloat32Array) { 13894 THREADED_TEST(FixedFloat32Array) {
14385 FixedTypedArrayTestHelper<i::FixedFloat32Array, i::FLOAT32_ELEMENTS, float>( 13895 FixedTypedArrayTestHelper<i::FixedFloat32Array, i::FLOAT32_ELEMENTS, float>(
14386 v8::kExternalFloat32Array, 13896 i::kExternalFloat32Array, -500, 500);
14387 -500, 500);
14388 } 13897 }
14389 13898
14390 13899
14391 THREADED_TEST(FixedFloat64Array) { 13900 THREADED_TEST(FixedFloat64Array) {
14392 FixedTypedArrayTestHelper<i::FixedFloat64Array, i::FLOAT64_ELEMENTS, float>( 13901 FixedTypedArrayTestHelper<i::FixedFloat64Array, i::FLOAT64_ELEMENTS, float>(
14393 v8::kExternalFloat64Array, 13902 i::kExternalFloat64Array, -500, 500);
14394 -500, 500);
14395 } 13903 }
14396 13904
14397 13905
14398 template <class ExternalArrayClass, class ElementType> 13906 template <typename ElementType, typename TypedArray, class ExternalArrayClass>
14399 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, 13907 void TypedArrayTestHelper(i::ExternalArrayType array_type, int64_t low,
14400 int64_t low, 13908 int64_t high) {
14401 int64_t high) {
14402 LocalContext context;
14403 i::Isolate* isolate = CcTest::i_isolate();
14404 i::Factory* factory = isolate->factory();
14405 v8::HandleScope scope(context->GetIsolate());
14406 const int kElementCount = 40;
14407 int element_size = ExternalArrayElementSize(array_type);
14408 ElementType* array_data =
14409 static_cast<ElementType*>(malloc(kElementCount * element_size));
14410 i::Handle<ExternalArrayClass> array =
14411 i::Handle<ExternalArrayClass>::cast(
14412 factory->NewExternalArray(kElementCount, array_type, array_data));
14413 // Force GC to trigger verification.
14414 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
14415 for (int i = 0; i < kElementCount; i++) {
14416 array->set(i, static_cast<ElementType>(i));
14417 }
14418 // Force GC to trigger verification.
14419 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
14420 for (int i = 0; i < kElementCount; i++) {
14421 CHECK_EQ(static_cast<int64_t>(i),
14422 static_cast<int64_t>(array->get_scalar(i)));
14423 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i]));
14424 }
14425
14426 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
14427 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj);
14428 // Set the elements to be the external array.
14429 obj->SetIndexedPropertiesToExternalArrayData(array_data,
14430 array_type,
14431 kElementCount);
14432 CHECK_EQ(1,
14433 static_cast<int>(
14434 i::Object::GetElement(
14435 isolate, jsobj, 1).ToHandleChecked()->Number()));
14436
14437 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
14438 context.local(), obj, kElementCount, array_type, low, high);
14439
14440 v8::Handle<v8::Value> result;
14441
14442 // Test more complex manipulations which cause eax to contain values
14443 // that won't be completely overwritten by loads from the arrays.
14444 // This catches bugs in the instructions used for the KeyedLoadIC
14445 // for byte and word types.
14446 {
14447 const int kXSize = 300;
14448 const int kYSize = 300;
14449 const int kLargeElementCount = kXSize * kYSize * 4;
14450 ElementType* large_array_data =
14451 static_cast<ElementType*>(malloc(kLargeElementCount * element_size));
14452 v8::Handle<v8::Object> large_obj = v8::Object::New(context->GetIsolate());
14453 // Set the elements to be the external array.
14454 large_obj->SetIndexedPropertiesToExternalArrayData(large_array_data,
14455 array_type,
14456 kLargeElementCount);
14457 context->Global()->Set(v8_str("large_array"), large_obj);
14458 // Initialize contents of a few rows.
14459 for (int x = 0; x < 300; x++) {
14460 int row = 0;
14461 int offset = row * 300 * 4;
14462 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
14463 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
14464 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
14465 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
14466 row = 150;
14467 offset = row * 300 * 4;
14468 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
14469 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
14470 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
14471 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
14472 row = 298;
14473 offset = row * 300 * 4;
14474 large_array_data[offset + 4 * x + 0] = (ElementType) 127;
14475 large_array_data[offset + 4 * x + 1] = (ElementType) 0;
14476 large_array_data[offset + 4 * x + 2] = (ElementType) 0;
14477 large_array_data[offset + 4 * x + 3] = (ElementType) 127;
14478 }
14479 // The goal of the code below is to make "offset" large enough
14480 // that the computation of the index (which goes into eax) has
14481 // high bits set which will not be overwritten by a byte or short
14482 // load.
14483 result = CompileRun("var failed = false;"
14484 "var offset = 0;"
14485 "for (var i = 0; i < 300; i++) {"
14486 " if (large_array[4 * i] != 127 ||"
14487 " large_array[4 * i + 1] != 0 ||"
14488 " large_array[4 * i + 2] != 0 ||"
14489 " large_array[4 * i + 3] != 127) {"
14490 " failed = true;"
14491 " }"
14492 "}"
14493 "offset = 150 * 300 * 4;"
14494 "for (var i = 0; i < 300; i++) {"
14495 " if (large_array[offset + 4 * i] != 127 ||"
14496 " large_array[offset + 4 * i + 1] != 0 ||"
14497 " large_array[offset + 4 * i + 2] != 0 ||"
14498 " large_array[offset + 4 * i + 3] != 127) {"
14499 " failed = true;"
14500 " }"
14501 "}"
14502 "offset = 298 * 300 * 4;"
14503 "for (var i = 0; i < 300; i++) {"
14504 " if (large_array[offset + 4 * i] != 127 ||"
14505 " large_array[offset + 4 * i + 1] != 0 ||"
14506 " large_array[offset + 4 * i + 2] != 0 ||"
14507 " large_array[offset + 4 * i + 3] != 127) {"
14508 " failed = true;"
14509 " }"
14510 "}"
14511 "!failed;");
14512 CHECK_EQ(true, result->BooleanValue());
14513 free(large_array_data);
14514 }
14515
14516 // The "" property descriptor is overloaded to store information about
14517 // the external array. Ensure that setting and accessing the "" property
14518 // works (it should overwrite the information cached about the external
14519 // array in the DescriptorArray) in various situations.
14520 result = CompileRun("ext_array[''] = 23; ext_array['']");
14521 CHECK_EQ(23, result->Int32Value());
14522
14523 // Property "" set after the external array is associated with the object.
14524 {
14525 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate());
14526 obj2->Set(v8_str("ee_test_field"),
14527 v8::Int32::New(context->GetIsolate(), 256));
14528 obj2->Set(v8_str(""), v8::Int32::New(context->GetIsolate(), 1503));
14529 // Set the elements to be the external array.
14530 obj2->SetIndexedPropertiesToExternalArrayData(array_data,
14531 array_type,
14532 kElementCount);
14533 context->Global()->Set(v8_str("ext_array"), obj2);
14534 result = CompileRun("ext_array['']");
14535 CHECK_EQ(1503, result->Int32Value());
14536 }
14537
14538 // Property "" set after the external array is associated with the object.
14539 {
14540 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate());
14541 obj2->Set(v8_str("ee_test_field_2"),
14542 v8::Int32::New(context->GetIsolate(), 256));
14543 // Set the elements to be the external array.
14544 obj2->SetIndexedPropertiesToExternalArrayData(array_data,
14545 array_type,
14546 kElementCount);
14547 obj2->Set(v8_str(""), v8::Int32::New(context->GetIsolate(), 1503));
14548 context->Global()->Set(v8_str("ext_array"), obj2);
14549 result = CompileRun("ext_array['']");
14550 CHECK_EQ(1503, result->Int32Value());
14551 }
14552
14553 // Should reuse the map from previous test.
14554 {
14555 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate());
14556 obj2->Set(v8_str("ee_test_field_2"),
14557 v8::Int32::New(context->GetIsolate(), 256));
14558 // Set the elements to be the external array. Should re-use the map
14559 // from previous test.
14560 obj2->SetIndexedPropertiesToExternalArrayData(array_data,
14561 array_type,
14562 kElementCount);
14563 context->Global()->Set(v8_str("ext_array"), obj2);
14564 result = CompileRun("ext_array['']");
14565 }
14566
14567 // Property "" is a constant function that shouldn't not be interfered with
14568 // when an external array is set.
14569 {
14570 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate());
14571 // Start
14572 obj2->Set(v8_str("ee_test_field3"),
14573 v8::Int32::New(context->GetIsolate(), 256));
14574
14575 // Add a constant function to an object.
14576 context->Global()->Set(v8_str("ext_array"), obj2);
14577 result = CompileRun("ext_array[''] = function() {return 1503;};"
14578 "ext_array['']();");
14579
14580 // Add an external array transition to the same map that
14581 // has the constant transition.
14582 v8::Handle<v8::Object> obj3 = v8::Object::New(context->GetIsolate());
14583 obj3->Set(v8_str("ee_test_field3"),
14584 v8::Int32::New(context->GetIsolate(), 256));
14585 obj3->SetIndexedPropertiesToExternalArrayData(array_data,
14586 array_type,
14587 kElementCount);
14588 context->Global()->Set(v8_str("ext_array"), obj3);
14589 }
14590
14591 // If a external array transition is in the map, it should get clobbered
14592 // by a constant function.
14593 {
14594 // Add an external array transition.
14595 v8::Handle<v8::Object> obj3 = v8::Object::New(context->GetIsolate());
14596 obj3->Set(v8_str("ee_test_field4"),
14597 v8::Int32::New(context->GetIsolate(), 256));
14598 obj3->SetIndexedPropertiesToExternalArrayData(array_data,
14599 array_type,
14600 kElementCount);
14601
14602 // Add a constant function to the same map that just got an external array
14603 // transition.
14604 v8::Handle<v8::Object> obj2 = v8::Object::New(context->GetIsolate());
14605 obj2->Set(v8_str("ee_test_field4"),
14606 v8::Int32::New(context->GetIsolate(), 256));
14607 context->Global()->Set(v8_str("ext_array"), obj2);
14608 result = CompileRun("ext_array[''] = function() {return 1503;};"
14609 "ext_array['']();");
14610 }
14611
14612 free(array_data);
14613 }
14614
14615
14616 THREADED_TEST(ExternalInt8Array) {
14617 ExternalArrayTestHelper<i::ExternalInt8Array, int8_t>(
14618 v8::kExternalInt8Array,
14619 -128,
14620 127);
14621 }
14622
14623
14624 THREADED_TEST(ExternalUint8Array) {
14625 ExternalArrayTestHelper<i::ExternalUint8Array, uint8_t>(
14626 v8::kExternalUint8Array,
14627 0,
14628 255);
14629 }
14630
14631
14632 THREADED_TEST(ExternalUint8ClampedArray) {
14633 ExternalArrayTestHelper<i::ExternalUint8ClampedArray, uint8_t>(
14634 v8::kExternalUint8ClampedArray,
14635 0,
14636 255);
14637 }
14638
14639
14640 THREADED_TEST(ExternalInt16Array) {
14641 ExternalArrayTestHelper<i::ExternalInt16Array, int16_t>(
14642 v8::kExternalInt16Array,
14643 -32768,
14644 32767);
14645 }
14646
14647
14648 THREADED_TEST(ExternalUint16Array) {
14649 ExternalArrayTestHelper<i::ExternalUint16Array, uint16_t>(
14650 v8::kExternalUint16Array,
14651 0,
14652 65535);
14653 }
14654
14655
14656 THREADED_TEST(ExternalInt32Array) {
14657 ExternalArrayTestHelper<i::ExternalInt32Array, int32_t>(
14658 v8::kExternalInt32Array,
14659 INT_MIN, // -2147483648
14660 INT_MAX); // 2147483647
14661 }
14662
14663
14664 THREADED_TEST(ExternalUint32Array) {
14665 ExternalArrayTestHelper<i::ExternalUint32Array, uint32_t>(
14666 v8::kExternalUint32Array,
14667 0,
14668 UINT_MAX); // 4294967295
14669 }
14670
14671
14672 THREADED_TEST(ExternalFloat32Array) {
14673 ExternalArrayTestHelper<i::ExternalFloat32Array, float>(
14674 v8::kExternalFloat32Array,
14675 -500,
14676 500);
14677 }
14678
14679
14680 THREADED_TEST(ExternalFloat64Array) {
14681 ExternalArrayTestHelper<i::ExternalFloat64Array, double>(
14682 v8::kExternalFloat64Array,
14683 -500,
14684 500);
14685 }
14686
14687
14688 THREADED_TEST(ExternalArrays) {
14689 TestExternalInt8Array();
14690 TestExternalUint8Array();
14691 TestExternalInt16Array();
14692 TestExternalUint16Array();
14693 TestExternalInt32Array();
14694 TestExternalUint32Array();
14695 TestExternalFloat32Array();
14696 }
14697
14698
14699 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) {
14700 LocalContext context;
14701 v8::HandleScope scope(context->GetIsolate());
14702 for (int size = 0; size < 100; size += 10) {
14703 int element_size = ExternalArrayElementSize(array_type);
14704 void* external_data = malloc(size * element_size);
14705 v8::Handle<v8::Object> obj = v8::Object::New(context->GetIsolate());
14706 obj->SetIndexedPropertiesToExternalArrayData(
14707 external_data, array_type, size);
14708 CHECK(obj->HasIndexedPropertiesInExternalArrayData());
14709 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData());
14710 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType());
14711 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength());
14712 free(external_data);
14713 }
14714 }
14715
14716
14717 THREADED_TEST(ExternalArrayInfo) {
14718 ExternalArrayInfoTestHelper(v8::kExternalInt8Array);
14719 ExternalArrayInfoTestHelper(v8::kExternalUint8Array);
14720 ExternalArrayInfoTestHelper(v8::kExternalInt16Array);
14721 ExternalArrayInfoTestHelper(v8::kExternalUint16Array);
14722 ExternalArrayInfoTestHelper(v8::kExternalInt32Array);
14723 ExternalArrayInfoTestHelper(v8::kExternalUint32Array);
14724 ExternalArrayInfoTestHelper(v8::kExternalFloat32Array);
14725 ExternalArrayInfoTestHelper(v8::kExternalFloat64Array);
14726 ExternalArrayInfoTestHelper(v8::kExternalUint8ClampedArray);
14727 }
14728
14729
14730 void ExtArrayLimitsHelper(v8::Isolate* isolate,
14731 v8::ExternalArrayType array_type,
14732 int size) {
14733 v8::Handle<v8::Object> obj = v8::Object::New(isolate);
14734 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
14735 last_location = last_message = NULL;
14736 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size);
14737 CHECK(!obj->HasIndexedPropertiesInExternalArrayData());
14738 CHECK(last_location);
14739 CHECK(last_message);
14740 }
14741
14742
14743 TEST(ExternalArrayLimits) {
14744 LocalContext context;
14745 v8::Isolate* isolate = context->GetIsolate();
14746 v8::HandleScope scope(isolate);
14747 ExtArrayLimitsHelper(isolate, v8::kExternalInt8Array, 0x40000000);
14748 ExtArrayLimitsHelper(isolate, v8::kExternalInt8Array, 0xffffffff);
14749 ExtArrayLimitsHelper(isolate, v8::kExternalUint8Array, 0x40000000);
14750 ExtArrayLimitsHelper(isolate, v8::kExternalUint8Array, 0xffffffff);
14751 ExtArrayLimitsHelper(isolate, v8::kExternalInt16Array, 0x40000000);
14752 ExtArrayLimitsHelper(isolate, v8::kExternalInt16Array, 0xffffffff);
14753 ExtArrayLimitsHelper(isolate, v8::kExternalUint16Array, 0x40000000);
14754 ExtArrayLimitsHelper(isolate, v8::kExternalUint16Array, 0xffffffff);
14755 ExtArrayLimitsHelper(isolate, v8::kExternalInt32Array, 0x40000000);
14756 ExtArrayLimitsHelper(isolate, v8::kExternalInt32Array, 0xffffffff);
14757 ExtArrayLimitsHelper(isolate, v8::kExternalUint32Array, 0x40000000);
14758 ExtArrayLimitsHelper(isolate, v8::kExternalUint32Array, 0xffffffff);
14759 ExtArrayLimitsHelper(isolate, v8::kExternalFloat32Array, 0x40000000);
14760 ExtArrayLimitsHelper(isolate, v8::kExternalFloat32Array, 0xffffffff);
14761 ExtArrayLimitsHelper(isolate, v8::kExternalFloat64Array, 0x40000000);
14762 ExtArrayLimitsHelper(isolate, v8::kExternalFloat64Array, 0xffffffff);
14763 ExtArrayLimitsHelper(isolate, v8::kExternalUint8ClampedArray, 0x40000000);
14764 ExtArrayLimitsHelper(isolate, v8::kExternalUint8ClampedArray, 0xffffffff);
14765 }
14766
14767
14768 template <typename ElementType, typename TypedArray,
14769 class ExternalArrayClass>
14770 void TypedArrayTestHelper(v8::ExternalArrayType array_type,
14771 int64_t low, int64_t high) {
14772 const int kElementCount = 50; 13909 const int kElementCount = 50;
14773 13910
14774 i::ScopedVector<ElementType> backing_store(kElementCount+2); 13911 i::ScopedVector<ElementType> backing_store(kElementCount+2);
14775 13912
14776 LocalContext env; 13913 LocalContext env;
14777 v8::Isolate* isolate = env->GetIsolate(); 13914 v8::Isolate* isolate = env->GetIsolate();
14778 v8::HandleScope handle_scope(isolate); 13915 v8::HandleScope handle_scope(isolate);
14779 13916
14780 Local<v8::ArrayBuffer> ab = 13917 Local<v8::ArrayBuffer> ab =
14781 v8::ArrayBuffer::New(isolate, backing_store.start(), 13918 v8::ArrayBuffer::New(isolate, backing_store.start(),
(...skipping 11 matching lines...) Expand all
14793 data[i] = static_cast<ElementType>(i); 13930 data[i] = static_cast<ElementType>(i);
14794 } 13931 }
14795 13932
14796 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( 13933 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
14797 env.local(), ta, kElementCount, array_type, low, high); 13934 env.local(), ta, kElementCount, array_type, low, high);
14798 } 13935 }
14799 13936
14800 13937
14801 THREADED_TEST(Uint8Array) { 13938 THREADED_TEST(Uint8Array) {
14802 TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUint8Array>( 13939 TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUint8Array>(
14803 v8::kExternalUint8Array, 0, 0xFF); 13940 i::kExternalUint8Array, 0, 0xFF);
14804 } 13941 }
14805 13942
14806 13943
14807 THREADED_TEST(Int8Array) { 13944 THREADED_TEST(Int8Array) {
14808 TypedArrayTestHelper<int8_t, v8::Int8Array, i::ExternalInt8Array>( 13945 TypedArrayTestHelper<int8_t, v8::Int8Array, i::ExternalInt8Array>(
14809 v8::kExternalInt8Array, -0x80, 0x7F); 13946 i::kExternalInt8Array, -0x80, 0x7F);
14810 } 13947 }
14811 13948
14812 13949
14813 THREADED_TEST(Uint16Array) { 13950 THREADED_TEST(Uint16Array) {
14814 TypedArrayTestHelper<uint16_t, 13951 TypedArrayTestHelper<uint16_t, v8::Uint16Array, i::ExternalUint16Array>(
14815 v8::Uint16Array, 13952 i::kExternalUint16Array, 0, 0xFFFF);
14816 i::ExternalUint16Array>(
14817 v8::kExternalUint16Array, 0, 0xFFFF);
14818 } 13953 }
14819 13954
14820 13955
14821 THREADED_TEST(Int16Array) { 13956 THREADED_TEST(Int16Array) {
14822 TypedArrayTestHelper<int16_t, v8::Int16Array, i::ExternalInt16Array>( 13957 TypedArrayTestHelper<int16_t, v8::Int16Array, i::ExternalInt16Array>(
14823 v8::kExternalInt16Array, -0x8000, 0x7FFF); 13958 i::kExternalInt16Array, -0x8000, 0x7FFF);
14824 } 13959 }
14825 13960
14826 13961
14827 THREADED_TEST(Uint32Array) { 13962 THREADED_TEST(Uint32Array) {
14828 TypedArrayTestHelper<uint32_t, v8::Uint32Array, i::ExternalUint32Array>( 13963 TypedArrayTestHelper<uint32_t, v8::Uint32Array, i::ExternalUint32Array>(
14829 v8::kExternalUint32Array, 0, UINT_MAX); 13964 i::kExternalUint32Array, 0, UINT_MAX);
14830 } 13965 }
14831 13966
14832 13967
14833 THREADED_TEST(Int32Array) { 13968 THREADED_TEST(Int32Array) {
14834 TypedArrayTestHelper<int32_t, v8::Int32Array, i::ExternalInt32Array>( 13969 TypedArrayTestHelper<int32_t, v8::Int32Array, i::ExternalInt32Array>(
14835 v8::kExternalInt32Array, INT_MIN, INT_MAX); 13970 i::kExternalInt32Array, INT_MIN, INT_MAX);
14836 } 13971 }
14837 13972
14838 13973
14839 THREADED_TEST(Float32Array) { 13974 THREADED_TEST(Float32Array) {
14840 TypedArrayTestHelper<float, v8::Float32Array, i::ExternalFloat32Array>( 13975 TypedArrayTestHelper<float, v8::Float32Array, i::ExternalFloat32Array>(
14841 v8::kExternalFloat32Array, -500, 500); 13976 i::kExternalFloat32Array, -500, 500);
14842 } 13977 }
14843 13978
14844 13979
14845 THREADED_TEST(Float64Array) { 13980 THREADED_TEST(Float64Array) {
14846 TypedArrayTestHelper<double, v8::Float64Array, i::ExternalFloat64Array>( 13981 TypedArrayTestHelper<double, v8::Float64Array, i::ExternalFloat64Array>(
14847 v8::kExternalFloat64Array, -500, 500); 13982 i::kExternalFloat64Array, -500, 500);
14848 } 13983 }
14849 13984
14850 13985
14851 THREADED_TEST(Uint8ClampedArray) { 13986 THREADED_TEST(Uint8ClampedArray) {
14852 TypedArrayTestHelper<uint8_t, 13987 TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray,
14853 v8::Uint8ClampedArray, i::ExternalUint8ClampedArray>( 13988 i::ExternalUint8ClampedArray>(
14854 v8::kExternalUint8ClampedArray, 0, 0xFF); 13989 i::kExternalUint8ClampedArray, 0, 0xFF);
14855 } 13990 }
14856 13991
14857 13992
14858 THREADED_TEST(DataView) { 13993 THREADED_TEST(DataView) {
14859 const int kSize = 50; 13994 const int kSize = 50;
14860 13995
14861 i::ScopedVector<uint8_t> backing_store(kSize+2); 13996 i::ScopedVector<uint8_t> backing_store(kSize+2);
14862 13997
14863 LocalContext env; 13998 LocalContext env;
14864 v8::Isolate* isolate = env->GetIsolate(); 13999 v8::Isolate* isolate = env->GetIsolate();
(...skipping 4711 matching lines...) Expand 10 before | Expand all | Expand 10 after
19576 SetterWhichSetsYOnThisTo23); 18711 SetterWhichSetsYOnThisTo23);
19577 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 18712 context->Global()->Set(v8_str("obj"), templ->NewInstance());
19578 18713
19579 CompileRun("function load(x) { return x.foo; }" 18714 CompileRun("function load(x) { return x.foo; }"
19580 "var o = Object.create(obj);" 18715 "var o = Object.create(obj);"
19581 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" 18716 "%OptimizeObjectForAddingMultipleProperties(obj, 1);"
19582 "load(o); load(o); load(o); load(o);"); 18717 "load(o); load(o); load(o); load(o);");
19583 } 18718 }
19584 18719
19585 18720
19586 THREADED_TEST(Regress3337) {
19587 LocalContext context;
19588 v8::Isolate* isolate = context->GetIsolate();
19589 v8::HandleScope scope(isolate);
19590 Local<v8::Object> o1 = Object::New(isolate);
19591 Local<v8::Object> o2 = Object::New(isolate);
19592 i::Handle<i::JSObject> io1 = v8::Utils::OpenHandle(*o1);
19593 i::Handle<i::JSObject> io2 = v8::Utils::OpenHandle(*o2);
19594 CHECK(io1->map() == io2->map());
19595 o1->SetIndexedPropertiesToExternalArrayData(
19596 NULL, v8::kExternalUint32Array, 0);
19597 o2->SetIndexedPropertiesToExternalArrayData(
19598 NULL, v8::kExternalUint32Array, 0);
19599 CHECK(io1->map() == io2->map());
19600 }
19601
19602
19603 THREADED_TEST(Regress137496) { 18721 THREADED_TEST(Regress137496) {
19604 i::FLAG_expose_gc = true; 18722 i::FLAG_expose_gc = true;
19605 LocalContext context; 18723 LocalContext context;
19606 v8::HandleScope scope(context->GetIsolate()); 18724 v8::HandleScope scope(context->GetIsolate());
19607 18725
19608 // Compile a try-finally clause where the finally block causes a GC 18726 // Compile a try-finally clause where the finally block causes a GC
19609 // while there still is a message pending for external reporting. 18727 // while there still is a message pending for external reporting.
19610 TryCatch try_catch; 18728 TryCatch try_catch;
19611 try_catch.SetVerbose(true); 18729 try_catch.SetVerbose(true);
19612 CompileRun("try { throw new Error(); } finally { gc(); }"); 18730 CompileRun("try { throw new Error(); } finally { gc(); }");
(...skipping 2287 matching lines...) Expand 10 before | Expand all | Expand 10 after
21900 21018
21901 { 21019 {
21902 v8::HandleScope handle_scope(isolate); 21020 v8::HandleScope handle_scope(isolate);
21903 21021
21904 // Should work 21022 // Should work
21905 v8::Local<v8::Object> obj = v8::Object::New(isolate); 21023 v8::Local<v8::Object> obj = v8::Object::New(isolate);
21906 21024
21907 USE(obj); 21025 USE(obj);
21908 } 21026 }
21909 } 21027 }
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-simplified-lowering.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698