| OLD | NEW |
| 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 14988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14999 "var x = obj.x;\n" | 14999 "var x = obj.x;\n" |
| 15000 "delete obj.y;\n" | 15000 "delete obj.y;\n" |
| 15001 "for (var i = 0; i < 5; i++) f(obj);"); | 15001 "for (var i = 0; i < 5; i++) f(obj);"); |
| 15002 // Detach the global object to make 'this' refer directly to the | 15002 // Detach the global object to make 'this' refer directly to the |
| 15003 // global object (not the proxy), and make sure that the dictionary | 15003 // global object (not the proxy), and make sure that the dictionary |
| 15004 // load IC doesn't mess up loading directly from the global object. | 15004 // load IC doesn't mess up loading directly from the global object. |
| 15005 context->DetachGlobal(); | 15005 context->DetachGlobal(); |
| 15006 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); | 15006 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); |
| 15007 } | 15007 } |
| 15008 | 15008 |
| 15009 static void CheckElementValue(i::Isolate* isolate, |
| 15010 int expected, |
| 15011 i::Handle<i::Object> obj, |
| 15012 int offset) { |
| 15013 i::Object* element = obj->GetElement(isolate, offset)->ToObjectChecked(); |
| 15014 CHECK_EQ(expected, i::Smi::cast(element)->value()); |
| 15015 } |
| 15016 |
| 15009 | 15017 |
| 15010 THREADED_TEST(PixelArray) { | 15018 THREADED_TEST(PixelArray) { |
| 15011 LocalContext context; | 15019 LocalContext context; |
| 15012 i::Factory* factory = i::Isolate::Current()->factory(); | 15020 i::Isolate* isolate = i::Isolate::Current(); |
| 15021 i::Factory* factory = isolate->factory(); |
| 15013 v8::HandleScope scope(context->GetIsolate()); | 15022 v8::HandleScope scope(context->GetIsolate()); |
| 15014 const int kElementCount = 260; | 15023 const int kElementCount = 260; |
| 15015 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); | 15024 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); |
| 15016 i::Handle<i::ExternalPixelArray> pixels = | 15025 i::Handle<i::ExternalPixelArray> pixels = |
| 15017 i::Handle<i::ExternalPixelArray>::cast( | 15026 i::Handle<i::ExternalPixelArray>::cast( |
| 15018 factory->NewExternalArray(kElementCount, | 15027 factory->NewExternalArray(kElementCount, |
| 15019 v8::kExternalPixelArray, | 15028 v8::kExternalPixelArray, |
| 15020 pixel_data)); | 15029 pixel_data)); |
| 15021 // Force GC to trigger verification. | 15030 // Force GC to trigger verification. |
| 15022 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 15031 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 15023 for (int i = 0; i < kElementCount; i++) { | 15032 for (int i = 0; i < kElementCount; i++) { |
| 15024 pixels->set(i, i % 256); | 15033 pixels->set(i, i % 256); |
| 15025 } | 15034 } |
| 15026 // Force GC to trigger verification. | 15035 // Force GC to trigger verification. |
| 15027 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 15036 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 15028 for (int i = 0; i < kElementCount; i++) { | 15037 for (int i = 0; i < kElementCount; i++) { |
| 15029 CHECK_EQ(i % 256, pixels->get_scalar(i)); | 15038 CHECK_EQ(i % 256, pixels->get_scalar(i)); |
| 15030 CHECK_EQ(i % 256, pixel_data[i]); | 15039 CHECK_EQ(i % 256, pixel_data[i]); |
| 15031 } | 15040 } |
| 15032 | 15041 |
| 15033 v8::Handle<v8::Object> obj = v8::Object::New(); | 15042 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 15034 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 15043 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 15035 // Set the elements to be the pixels. | 15044 // Set the elements to be the pixels. |
| 15036 // jsobj->set_elements(*pixels); | 15045 // jsobj->set_elements(*pixels); |
| 15037 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); | 15046 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount); |
| 15038 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | 15047 CheckElementValue(isolate, 1, jsobj, 1); |
| 15039 obj->Set(v8_str("field"), v8::Int32::New(1503)); | 15048 obj->Set(v8_str("field"), v8::Int32::New(1503)); |
| 15040 context->Global()->Set(v8_str("pixels"), obj); | 15049 context->Global()->Set(v8_str("pixels"), obj); |
| 15041 v8::Handle<v8::Value> result = CompileRun("pixels.field"); | 15050 v8::Handle<v8::Value> result = CompileRun("pixels.field"); |
| 15042 CHECK_EQ(1503, result->Int32Value()); | 15051 CHECK_EQ(1503, result->Int32Value()); |
| 15043 result = CompileRun("pixels[1]"); | 15052 result = CompileRun("pixels[1]"); |
| 15044 CHECK_EQ(1, result->Int32Value()); | 15053 CHECK_EQ(1, result->Int32Value()); |
| 15045 | 15054 |
| 15046 result = CompileRun("var sum = 0;" | 15055 result = CompileRun("var sum = 0;" |
| 15047 "for (var i = 0; i < 8; i++) {" | 15056 "for (var i = 0; i < 8; i++) {" |
| 15048 " sum += pixels[i] = pixels[i] = -i;" | 15057 " sum += pixels[i] = pixels[i] = -i;" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15085 "sum;"); | 15094 "sum;"); |
| 15086 CHECK_EQ(28, result->Int32Value()); | 15095 CHECK_EQ(28, result->Int32Value()); |
| 15087 | 15096 |
| 15088 i::Handle<i::Smi> value(i::Smi::FromInt(2), | 15097 i::Handle<i::Smi> value(i::Smi::FromInt(2), |
| 15089 reinterpret_cast<i::Isolate*>(context->GetIsolate())); | 15098 reinterpret_cast<i::Isolate*>(context->GetIsolate())); |
| 15090 i::Handle<i::Object> no_failure; | 15099 i::Handle<i::Object> no_failure; |
| 15091 no_failure = | 15100 no_failure = |
| 15092 i::JSObject::SetElement(jsobj, 1, value, NONE, i::kNonStrictMode); | 15101 i::JSObject::SetElement(jsobj, 1, value, NONE, i::kNonStrictMode); |
| 15093 ASSERT(!no_failure.is_null()); | 15102 ASSERT(!no_failure.is_null()); |
| 15094 i::USE(no_failure); | 15103 i::USE(no_failure); |
| 15095 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | 15104 CheckElementValue(isolate, 2, jsobj, 1); |
| 15096 *value.location() = i::Smi::FromInt(256); | 15105 *value.location() = i::Smi::FromInt(256); |
| 15097 no_failure = | 15106 no_failure = |
| 15098 i::JSObject::SetElement(jsobj, 1, value, NONE, i::kNonStrictMode); | 15107 i::JSObject::SetElement(jsobj, 1, value, NONE, i::kNonStrictMode); |
| 15099 ASSERT(!no_failure.is_null()); | 15108 ASSERT(!no_failure.is_null()); |
| 15100 i::USE(no_failure); | 15109 i::USE(no_failure); |
| 15101 CHECK_EQ(255, | 15110 CheckElementValue(isolate, 255, jsobj, 1); |
| 15102 i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | |
| 15103 *value.location() = i::Smi::FromInt(-1); | 15111 *value.location() = i::Smi::FromInt(-1); |
| 15104 no_failure = | 15112 no_failure = |
| 15105 i::JSObject::SetElement(jsobj, 1, value, NONE, i::kNonStrictMode); | 15113 i::JSObject::SetElement(jsobj, 1, value, NONE, i::kNonStrictMode); |
| 15106 ASSERT(!no_failure.is_null()); | 15114 ASSERT(!no_failure.is_null()); |
| 15107 i::USE(no_failure); | 15115 i::USE(no_failure); |
| 15108 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | 15116 CheckElementValue(isolate, 0, jsobj, 1); |
| 15109 | 15117 |
| 15110 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15118 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15111 " pixels[i] = (i * 65) - 109;" | 15119 " pixels[i] = (i * 65) - 109;" |
| 15112 "}" | 15120 "}" |
| 15113 "pixels[1] + pixels[6];"); | 15121 "pixels[1] + pixels[6];"); |
| 15114 CHECK_EQ(255, result->Int32Value()); | 15122 CHECK_EQ(255, result->Int32Value()); |
| 15115 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(0)->ToObjectChecked())->value()); | 15123 CheckElementValue(isolate, 0, jsobj, 0); |
| 15116 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | 15124 CheckElementValue(isolate, 0, jsobj, 1); |
| 15117 CHECK_EQ(21, | 15125 CheckElementValue(isolate, 21, jsobj, 2); |
| 15118 i::Smi::cast(jsobj->GetElement(2)->ToObjectChecked())->value()); | 15126 CheckElementValue(isolate, 86, jsobj, 3); |
| 15119 CHECK_EQ(86, | 15127 CheckElementValue(isolate, 151, jsobj, 4); |
| 15120 i::Smi::cast(jsobj->GetElement(3)->ToObjectChecked())->value()); | 15128 CheckElementValue(isolate, 216, jsobj, 5); |
| 15121 CHECK_EQ(151, | 15129 CheckElementValue(isolate, 255, jsobj, 6); |
| 15122 i::Smi::cast(jsobj->GetElement(4)->ToObjectChecked())->value()); | 15130 CheckElementValue(isolate, 255, jsobj, 7); |
| 15123 CHECK_EQ(216, | |
| 15124 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); | |
| 15125 CHECK_EQ(255, | |
| 15126 i::Smi::cast(jsobj->GetElement(6)->ToObjectChecked())->value()); | |
| 15127 CHECK_EQ(255, | |
| 15128 i::Smi::cast(jsobj->GetElement(7)->ToObjectChecked())->value()); | |
| 15129 result = CompileRun("var sum = 0;" | 15131 result = CompileRun("var sum = 0;" |
| 15130 "for (var i = 0; i < 8; i++) {" | 15132 "for (var i = 0; i < 8; i++) {" |
| 15131 " sum += pixels[i];" | 15133 " sum += pixels[i];" |
| 15132 "}" | 15134 "}" |
| 15133 "sum;"); | 15135 "sum;"); |
| 15134 CHECK_EQ(984, result->Int32Value()); | 15136 CHECK_EQ(984, result->Int32Value()); |
| 15135 | 15137 |
| 15136 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15138 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15137 " pixels[i] = (i * 1.1);" | 15139 " pixels[i] = (i * 1.1);" |
| 15138 "}" | 15140 "}" |
| 15139 "pixels[1] + pixels[6];"); | 15141 "pixels[1] + pixels[6];"); |
| 15140 CHECK_EQ(8, result->Int32Value()); | 15142 CHECK_EQ(8, result->Int32Value()); |
| 15141 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(0)->ToObjectChecked())->value()); | 15143 CheckElementValue(isolate, 0, jsobj, 0); |
| 15142 CHECK_EQ(1, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); | 15144 CheckElementValue(isolate, 1, jsobj, 1); |
| 15143 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(2)->ToObjectChecked())->value()); | 15145 CheckElementValue(isolate, 2, jsobj, 2); |
| 15144 CHECK_EQ(3, i::Smi::cast(jsobj->GetElement(3)->ToObjectChecked())->value()); | 15146 CheckElementValue(isolate, 3, jsobj, 3); |
| 15145 CHECK_EQ(4, i::Smi::cast(jsobj->GetElement(4)->ToObjectChecked())->value()); | 15147 CheckElementValue(isolate, 4, jsobj, 4); |
| 15146 CHECK_EQ(6, i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); | 15148 CheckElementValue(isolate, 6, jsobj, 5); |
| 15147 CHECK_EQ(7, i::Smi::cast(jsobj->GetElement(6)->ToObjectChecked())->value()); | 15149 CheckElementValue(isolate, 7, jsobj, 6); |
| 15148 CHECK_EQ(8, i::Smi::cast(jsobj->GetElement(7)->ToObjectChecked())->value()); | 15150 CheckElementValue(isolate, 8, jsobj, 7); |
| 15149 | 15151 |
| 15150 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15152 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15151 " pixels[7] = undefined;" | 15153 " pixels[7] = undefined;" |
| 15152 "}" | 15154 "}" |
| 15153 "pixels[7];"); | 15155 "pixels[7];"); |
| 15154 CHECK_EQ(0, result->Int32Value()); | 15156 CHECK_EQ(0, result->Int32Value()); |
| 15155 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(7)->ToObjectChecked())->value()); | 15157 CheckElementValue(isolate, 0, jsobj, 7); |
| 15156 | 15158 |
| 15157 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15159 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15158 " pixels[6] = '2.3';" | 15160 " pixels[6] = '2.3';" |
| 15159 "}" | 15161 "}" |
| 15160 "pixels[6];"); | 15162 "pixels[6];"); |
| 15161 CHECK_EQ(2, result->Int32Value()); | 15163 CHECK_EQ(2, result->Int32Value()); |
| 15162 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(6)->ToObjectChecked())->value()); | 15164 CheckElementValue(isolate, 2, jsobj, 6); |
| 15163 | 15165 |
| 15164 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15166 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15165 " pixels[5] = NaN;" | 15167 " pixels[5] = NaN;" |
| 15166 "}" | 15168 "}" |
| 15167 "pixels[5];"); | 15169 "pixels[5];"); |
| 15168 CHECK_EQ(0, result->Int32Value()); | 15170 CHECK_EQ(0, result->Int32Value()); |
| 15169 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); | 15171 CheckElementValue(isolate, 0, jsobj, 5); |
| 15170 | 15172 |
| 15171 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15173 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15172 " pixels[8] = Infinity;" | 15174 " pixels[8] = Infinity;" |
| 15173 "}" | 15175 "}" |
| 15174 "pixels[8];"); | 15176 "pixels[8];"); |
| 15175 CHECK_EQ(255, result->Int32Value()); | 15177 CHECK_EQ(255, result->Int32Value()); |
| 15176 CHECK_EQ(255, | 15178 CheckElementValue(isolate, 255, jsobj, 8); |
| 15177 i::Smi::cast(jsobj->GetElement(8)->ToObjectChecked())->value()); | |
| 15178 | 15179 |
| 15179 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15180 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15180 " pixels[9] = -Infinity;" | 15181 " pixels[9] = -Infinity;" |
| 15181 "}" | 15182 "}" |
| 15182 "pixels[9];"); | 15183 "pixels[9];"); |
| 15183 CHECK_EQ(0, result->Int32Value()); | 15184 CHECK_EQ(0, result->Int32Value()); |
| 15184 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(9)->ToObjectChecked())->value()); | 15185 CheckElementValue(isolate, 0, jsobj, 9); |
| 15185 | 15186 |
| 15186 result = CompileRun("pixels[3] = 33;" | 15187 result = CompileRun("pixels[3] = 33;" |
| 15187 "delete pixels[3];" | 15188 "delete pixels[3];" |
| 15188 "pixels[3];"); | 15189 "pixels[3];"); |
| 15189 CHECK_EQ(33, result->Int32Value()); | 15190 CHECK_EQ(33, result->Int32Value()); |
| 15190 | 15191 |
| 15191 result = CompileRun("pixels[0] = 10; pixels[1] = 11;" | 15192 result = CompileRun("pixels[0] = 10; pixels[1] = 11;" |
| 15192 "pixels[2] = 12; pixels[3] = 13;" | 15193 "pixels[2] = 12; pixels[3] = 13;" |
| 15193 "pixels.__defineGetter__('2'," | 15194 "pixels.__defineGetter__('2'," |
| 15194 "function() { return 120; });" | 15195 "function() { return 120; });" |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15491 | 15492 |
| 15492 | 15493 |
| 15493 template <class ExternalArrayClass, class ElementType> | 15494 template <class ExternalArrayClass, class ElementType> |
| 15494 static void ObjectWithExternalArrayTestHelper( | 15495 static void ObjectWithExternalArrayTestHelper( |
| 15495 Handle<Context> context, | 15496 Handle<Context> context, |
| 15496 v8::Handle<Object> obj, | 15497 v8::Handle<Object> obj, |
| 15497 int element_count, | 15498 int element_count, |
| 15498 v8::ExternalArrayType array_type, | 15499 v8::ExternalArrayType array_type, |
| 15499 int64_t low, int64_t high) { | 15500 int64_t low, int64_t high) { |
| 15500 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 15501 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 15502 i::Isolate* isolate = jsobj->GetIsolate(); |
| 15501 obj->Set(v8_str("field"), v8::Int32::New(1503)); | 15503 obj->Set(v8_str("field"), v8::Int32::New(1503)); |
| 15502 context->Global()->Set(v8_str("ext_array"), obj); | 15504 context->Global()->Set(v8_str("ext_array"), obj); |
| 15503 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); | 15505 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); |
| 15504 CHECK_EQ(1503, result->Int32Value()); | 15506 CHECK_EQ(1503, result->Int32Value()); |
| 15505 result = CompileRun("ext_array[1]"); | 15507 result = CompileRun("ext_array[1]"); |
| 15506 CHECK_EQ(1, result->Int32Value()); | 15508 CHECK_EQ(1, result->Int32Value()); |
| 15507 | 15509 |
| 15508 // Check pass through of assigned smis | 15510 // Check pass through of assigned smis |
| 15509 result = CompileRun("var sum = 0;" | 15511 result = CompileRun("var sum = 0;" |
| 15510 "for (var i = 0; i < 8; i++) {" | 15512 "for (var i = 0; i < 8; i++) {" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15632 CHECK_EQ(false, result->BooleanValue()); | 15634 CHECK_EQ(false, result->BooleanValue()); |
| 15633 | 15635 |
| 15634 // Check other boundary conditions, values and operations. | 15636 // Check other boundary conditions, values and operations. |
| 15635 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15637 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15636 " ext_array[7] = undefined;" | 15638 " ext_array[7] = undefined;" |
| 15637 "}" | 15639 "}" |
| 15638 "ext_array[7];"); | 15640 "ext_array[7];"); |
| 15639 CHECK_EQ(0, result->Int32Value()); | 15641 CHECK_EQ(0, result->Int32Value()); |
| 15640 if (array_type == v8::kExternalDoubleArray || | 15642 if (array_type == v8::kExternalDoubleArray || |
| 15641 array_type == v8::kExternalFloatArray) { | 15643 array_type == v8::kExternalFloatArray) { |
| 15642 CHECK_EQ( | 15644 CHECK_EQ(static_cast<int>(i::OS::nan_value()), |
| 15643 static_cast<int>(i::OS::nan_value()), | 15645 static_cast<int>( |
| 15644 static_cast<int>(jsobj->GetElement(7)->ToObjectChecked()->Number())); | 15646 jsobj->GetElement(isolate, 7)->ToObjectChecked()->Number())); |
| 15645 } else { | 15647 } else { |
| 15646 CHECK_EQ(0, static_cast<int>( | 15648 CheckElementValue(isolate, 0, jsobj, 7); |
| 15647 jsobj->GetElement(7)->ToObjectChecked()->Number())); | |
| 15648 } | 15649 } |
| 15649 | 15650 |
| 15650 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15651 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15651 " ext_array[6] = '2.3';" | 15652 " ext_array[6] = '2.3';" |
| 15652 "}" | 15653 "}" |
| 15653 "ext_array[6];"); | 15654 "ext_array[6];"); |
| 15654 CHECK_EQ(2, result->Int32Value()); | 15655 CHECK_EQ(2, result->Int32Value()); |
| 15655 CHECK_EQ( | 15656 CHECK_EQ(2, |
| 15656 2, static_cast<int>(jsobj->GetElement(6)->ToObjectChecked()->Number())); | 15657 static_cast<int>( |
| 15658 jsobj->GetElement(isolate, 6)->ToObjectChecked()->Number())); |
| 15657 | 15659 |
| 15658 if (array_type != v8::kExternalFloatArray && | 15660 if (array_type != v8::kExternalFloatArray && |
| 15659 array_type != v8::kExternalDoubleArray) { | 15661 array_type != v8::kExternalDoubleArray) { |
| 15660 // Though the specification doesn't state it, be explicit about | 15662 // Though the specification doesn't state it, be explicit about |
| 15661 // converting NaNs and +/-Infinity to zero. | 15663 // converting NaNs and +/-Infinity to zero. |
| 15662 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15664 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15663 " ext_array[i] = 5;" | 15665 " ext_array[i] = 5;" |
| 15664 "}" | 15666 "}" |
| 15665 "for (var i = 0; i < 8; i++) {" | 15667 "for (var i = 0; i < 8; i++) {" |
| 15666 " ext_array[i] = NaN;" | 15668 " ext_array[i] = NaN;" |
| 15667 "}" | 15669 "}" |
| 15668 "ext_array[5];"); | 15670 "ext_array[5];"); |
| 15669 CHECK_EQ(0, result->Int32Value()); | 15671 CHECK_EQ(0, result->Int32Value()); |
| 15670 CHECK_EQ(0, | 15672 CheckElementValue(isolate, 0, jsobj, 5); |
| 15671 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); | |
| 15672 | 15673 |
| 15673 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15674 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15674 " ext_array[i] = 5;" | 15675 " ext_array[i] = 5;" |
| 15675 "}" | 15676 "}" |
| 15676 "for (var i = 0; i < 8; i++) {" | 15677 "for (var i = 0; i < 8; i++) {" |
| 15677 " ext_array[i] = Infinity;" | 15678 " ext_array[i] = Infinity;" |
| 15678 "}" | 15679 "}" |
| 15679 "ext_array[5];"); | 15680 "ext_array[5];"); |
| 15680 int expected_value = | 15681 int expected_value = |
| 15681 (array_type == v8::kExternalPixelArray) ? 255 : 0; | 15682 (array_type == v8::kExternalPixelArray) ? 255 : 0; |
| 15682 CHECK_EQ(expected_value, result->Int32Value()); | 15683 CHECK_EQ(expected_value, result->Int32Value()); |
| 15683 CHECK_EQ(expected_value, | 15684 CheckElementValue(isolate, expected_value, jsobj, 5); |
| 15684 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); | |
| 15685 | 15685 |
| 15686 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15686 result = CompileRun("for (var i = 0; i < 8; i++) {" |
| 15687 " ext_array[i] = 5;" | 15687 " ext_array[i] = 5;" |
| 15688 "}" | 15688 "}" |
| 15689 "for (var i = 0; i < 8; i++) {" | 15689 "for (var i = 0; i < 8; i++) {" |
| 15690 " ext_array[i] = -Infinity;" | 15690 " ext_array[i] = -Infinity;" |
| 15691 "}" | 15691 "}" |
| 15692 "ext_array[5];"); | 15692 "ext_array[5];"); |
| 15693 CHECK_EQ(0, result->Int32Value()); | 15693 CHECK_EQ(0, result->Int32Value()); |
| 15694 CHECK_EQ(0, | 15694 CheckElementValue(isolate, 0, jsobj, 5); |
| 15695 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); | |
| 15696 | 15695 |
| 15697 // Check truncation behavior of integral arrays. | 15696 // Check truncation behavior of integral arrays. |
| 15698 const char* unsigned_data = | 15697 const char* unsigned_data = |
| 15699 "var source_data = [0.6, 10.6];" | 15698 "var source_data = [0.6, 10.6];" |
| 15700 "var expected_results = [0, 10];"; | 15699 "var expected_results = [0, 10];"; |
| 15701 const char* signed_data = | 15700 const char* signed_data = |
| 15702 "var source_data = [0.6, 10.6, -0.6, -10.6];" | 15701 "var source_data = [0.6, 10.6, -0.6, -10.6];" |
| 15703 "var expected_results = [0, 10, 0, -10];"; | 15702 "var expected_results = [0, 10, 0, -10];"; |
| 15704 const char* pixel_data = | 15703 const char* pixel_data = |
| 15705 "var source_data = [0.6, 10.6];" | 15704 "var source_data = [0.6, 10.6];" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15791 result = CompileRun("ext_array[1] = 23;"); | 15790 result = CompileRun("ext_array[1] = 23;"); |
| 15792 CHECK_EQ(23, result->Int32Value()); | 15791 CHECK_EQ(23, result->Int32Value()); |
| 15793 } | 15792 } |
| 15794 | 15793 |
| 15795 | 15794 |
| 15796 template <class ExternalArrayClass, class ElementType> | 15795 template <class ExternalArrayClass, class ElementType> |
| 15797 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, | 15796 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, |
| 15798 int64_t low, | 15797 int64_t low, |
| 15799 int64_t high) { | 15798 int64_t high) { |
| 15800 LocalContext context; | 15799 LocalContext context; |
| 15801 i::Factory* factory = i::Isolate::Current()->factory(); | 15800 i::Isolate* isolate = i::Isolate::Current(); |
| 15801 i::Factory* factory = isolate->factory(); |
| 15802 v8::HandleScope scope(context->GetIsolate()); | 15802 v8::HandleScope scope(context->GetIsolate()); |
| 15803 const int kElementCount = 40; | 15803 const int kElementCount = 40; |
| 15804 int element_size = ExternalArrayElementSize(array_type); | 15804 int element_size = ExternalArrayElementSize(array_type); |
| 15805 ElementType* array_data = | 15805 ElementType* array_data = |
| 15806 static_cast<ElementType*>(malloc(kElementCount * element_size)); | 15806 static_cast<ElementType*>(malloc(kElementCount * element_size)); |
| 15807 i::Handle<ExternalArrayClass> array = | 15807 i::Handle<ExternalArrayClass> array = |
| 15808 i::Handle<ExternalArrayClass>::cast( | 15808 i::Handle<ExternalArrayClass>::cast( |
| 15809 factory->NewExternalArray(kElementCount, array_type, array_data)); | 15809 factory->NewExternalArray(kElementCount, array_type, array_data)); |
| 15810 // Force GC to trigger verification. | 15810 // Force GC to trigger verification. |
| 15811 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 15811 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 15812 for (int i = 0; i < kElementCount; i++) { | 15812 for (int i = 0; i < kElementCount; i++) { |
| 15813 array->set(i, static_cast<ElementType>(i)); | 15813 array->set(i, static_cast<ElementType>(i)); |
| 15814 } | 15814 } |
| 15815 // Force GC to trigger verification. | 15815 // Force GC to trigger verification. |
| 15816 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 15816 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 15817 for (int i = 0; i < kElementCount; i++) { | 15817 for (int i = 0; i < kElementCount; i++) { |
| 15818 CHECK_EQ(static_cast<int64_t>(i), | 15818 CHECK_EQ(static_cast<int64_t>(i), |
| 15819 static_cast<int64_t>(array->get_scalar(i))); | 15819 static_cast<int64_t>(array->get_scalar(i))); |
| 15820 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); | 15820 CHECK_EQ(static_cast<int64_t>(i), static_cast<int64_t>(array_data[i])); |
| 15821 } | 15821 } |
| 15822 | 15822 |
| 15823 v8::Handle<v8::Object> obj = v8::Object::New(); | 15823 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 15824 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 15824 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 15825 // Set the elements to be the external array. | 15825 // Set the elements to be the external array. |
| 15826 obj->SetIndexedPropertiesToExternalArrayData(array_data, | 15826 obj->SetIndexedPropertiesToExternalArrayData(array_data, |
| 15827 array_type, | 15827 array_type, |
| 15828 kElementCount); | 15828 kElementCount); |
| 15829 CHECK_EQ( | 15829 CHECK_EQ(1, |
| 15830 1, static_cast<int>(jsobj->GetElement(1)->ToObjectChecked()->Number())); | 15830 static_cast<int>( |
| 15831 jsobj->GetElement(isolate, 1)->ToObjectChecked()->Number())); |
| 15831 | 15832 |
| 15832 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( | 15833 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>( |
| 15833 context.local(), obj, kElementCount, array_type, low, high); | 15834 context.local(), obj, kElementCount, array_type, low, high); |
| 15834 | 15835 |
| 15835 v8::Handle<v8::Value> result; | 15836 v8::Handle<v8::Value> result; |
| 15836 | 15837 |
| 15837 // Test more complex manipulations which cause eax to contain values | 15838 // Test more complex manipulations which cause eax to contain values |
| 15838 // that won't be completely overwritten by loads from the arrays. | 15839 // that won't be completely overwritten by loads from the arrays. |
| 15839 // This catches bugs in the instructions used for the KeyedLoadIC | 15840 // This catches bugs in the instructions used for the KeyedLoadIC |
| 15840 // for byte and word types. | 15841 // for byte and word types. |
| (...skipping 4571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20412 "setAge(100);" | 20413 "setAge(100);" |
| 20413 "setAge(101);" | 20414 "setAge(101);" |
| 20414 "setAge(102);" | 20415 "setAge(102);" |
| 20415 "%OptimizeFunctionOnNextCall(setAge);" | 20416 "%OptimizeFunctionOnNextCall(setAge);" |
| 20416 "setAge(103);"); | 20417 "setAge(103);"); |
| 20417 ExpectInt32("obj.age", 100000); | 20418 ExpectInt32("obj.age", 100000); |
| 20418 ExpectInt32("obj.interceptor_age", 103); | 20419 ExpectInt32("obj.interceptor_age", 103); |
| 20419 } | 20420 } |
| 20420 | 20421 |
| 20421 #endif // V8_OS_POSIX | 20422 #endif // V8_OS_POSIX |
| OLD | NEW |