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 16124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16135 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); | 16135 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
16136 i::Isolate* isolate = jsobj->GetIsolate(); | 16136 i::Isolate* isolate = jsobj->GetIsolate(); |
16137 obj->Set(v8_str("field"), | 16137 obj->Set(v8_str("field"), |
16138 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503)); | 16138 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503)); |
16139 context->Global()->Set(v8_str("ext_array"), obj); | 16139 context->Global()->Set(v8_str("ext_array"), obj); |
16140 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); | 16140 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); |
16141 CHECK_EQ(1503, result->Int32Value()); | 16141 CHECK_EQ(1503, result->Int32Value()); |
16142 result = CompileRun("ext_array[1]"); | 16142 result = CompileRun("ext_array[1]"); |
16143 CHECK_EQ(1, result->Int32Value()); | 16143 CHECK_EQ(1, result->Int32Value()); |
16144 | 16144 |
16145 // Check pass through of assigned smis | |
16146 result = CompileRun("var sum = 0;" | |
16147 "for (var i = 0; i < 8; i++) {" | |
16148 " sum += ext_array[i] = ext_array[i] = -i;" | |
16149 "}" | |
16150 "sum;"); | |
16151 CHECK_EQ(-28, result->Int32Value()); | |
16152 | |
16153 // Check assigned smis | 16145 // Check assigned smis |
16154 result = CompileRun("for (var i = 0; i < 8; i++) {" | 16146 result = CompileRun("for (var i = 0; i < 8; i++) {" |
16155 " ext_array[i] = i;" | 16147 " ext_array[i] = i;" |
16156 "}" | 16148 "}" |
16157 "var sum = 0;" | 16149 "var sum = 0;" |
16158 "for (var i = 0; i < 8; i++) {" | 16150 "for (var i = 0; i < 8; i++) {" |
16159 " sum += ext_array[i];" | 16151 " sum += ext_array[i];" |
16160 "}" | 16152 "}" |
16161 "sum;"); | 16153 "sum;"); |
| 16154 |
16162 CHECK_EQ(28, result->Int32Value()); | 16155 CHECK_EQ(28, result->Int32Value()); |
| 16156 // Check pass through of assigned smis |
| 16157 result = CompileRun("var sum = 0;" |
| 16158 "for (var i = 0; i < 8; i++) {" |
| 16159 " sum += ext_array[i] = ext_array[i] = -i;" |
| 16160 "}" |
| 16161 "sum;"); |
| 16162 CHECK_EQ(-28, result->Int32Value()); |
| 16163 |
16163 | 16164 |
16164 // Check assigned smis in reverse order | 16165 // Check assigned smis in reverse order |
16165 result = CompileRun("for (var i = 8; --i >= 0; ) {" | 16166 result = CompileRun("for (var i = 8; --i >= 0; ) {" |
16166 " ext_array[i] = i;" | 16167 " ext_array[i] = i;" |
16167 "}" | 16168 "}" |
16168 "var sum = 0;" | 16169 "var sum = 0;" |
16169 "for (var i = 0; i < 8; i++) {" | 16170 "for (var i = 0; i < 8; i++) {" |
16170 " sum += ext_array[i];" | 16171 " sum += ext_array[i];" |
16171 "}" | 16172 "}" |
16172 "sum;"); | 16173 "sum;"); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16420 "js_array.__proto__ = ext_array;" | 16421 "js_array.__proto__ = ext_array;" |
16421 "js_array.concat(ext_array);"); | 16422 "js_array.concat(ext_array);"); |
16422 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); | 16423 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); |
16423 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); | 16424 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); |
16424 | 16425 |
16425 result = CompileRun("ext_array[1] = 23;"); | 16426 result = CompileRun("ext_array[1] = 23;"); |
16426 CHECK_EQ(23, result->Int32Value()); | 16427 CHECK_EQ(23, result->Int32Value()); |
16427 } | 16428 } |
16428 | 16429 |
16429 | 16430 |
| 16431 template <class FixedTypedArrayClass, |
| 16432 i::ElementsKind elements_kind, |
| 16433 class ElementType> |
| 16434 static void FixedTypedArrayTestHelper( |
| 16435 v8::ExternalArrayType array_type, |
| 16436 ElementType low, |
| 16437 ElementType high) { |
| 16438 i::FLAG_allow_natives_syntax = true; |
| 16439 LocalContext context; |
| 16440 i::Isolate* isolate = CcTest::i_isolate(); |
| 16441 i::Factory* factory = isolate->factory(); |
| 16442 v8::HandleScope scope(context->GetIsolate()); |
| 16443 const int kElementCount = 260; |
| 16444 i::Handle<FixedTypedArrayClass> fixed_array = |
| 16445 i::Handle<FixedTypedArrayClass>::cast( |
| 16446 factory->NewFixedTypedArray(kElementCount, array_type)); |
| 16447 CHECK_EQ(FixedTypedArrayClass::kInstanceType, |
| 16448 fixed_array->map()->instance_type()); |
| 16449 CHECK_EQ(kElementCount, fixed_array->length()); |
| 16450 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 16451 for (int i = 0; i < kElementCount; i++) { |
| 16452 fixed_array->set(i, static_cast<ElementType>(i)); |
| 16453 } |
| 16454 // Force GC to trigger verification. |
| 16455 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 16456 for (int i = 0; i < kElementCount; i++) { |
| 16457 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)), |
| 16458 static_cast<int64_t>(fixed_array->get_scalar(i))); |
| 16459 } |
| 16460 v8::Handle<v8::Object> obj = v8::Object::New(CcTest::isolate()); |
| 16461 i::Handle<i::JSObject> jsobj = v8::Utils::OpenHandle(*obj); |
| 16462 i::Handle<i::Map> fixed_array_map = |
| 16463 isolate->factory()->GetElementsTransitionMap(jsobj, elements_kind); |
| 16464 jsobj->set_map(*fixed_array_map); |
| 16465 jsobj->set_elements(*fixed_array); |
| 16466 |
| 16467 ObjectWithExternalArrayTestHelper<FixedTypedArrayClass, ElementType>( |
| 16468 context.local(), obj, kElementCount, array_type, low, high); |
| 16469 } |
| 16470 |
| 16471 |
| 16472 THREADED_TEST(FixedUint8Array) { |
| 16473 FixedTypedArrayTestHelper<i::FixedUint8Array, i::UINT8_ELEMENTS, uint8_t>( |
| 16474 v8::kExternalUnsignedByteArray, |
| 16475 0x0, 0xFF); |
| 16476 } |
| 16477 |
| 16478 |
| 16479 THREADED_TEST(FixedUint8ClampedArray) { |
| 16480 FixedTypedArrayTestHelper<i::FixedUint8ClampedArray, |
| 16481 i::UINT8_CLAMPED_ELEMENTS, uint8_t>( |
| 16482 v8::kExternalPixelArray, |
| 16483 0x0, 0xFF); |
| 16484 } |
| 16485 |
| 16486 |
| 16487 THREADED_TEST(FixedInt8Array) { |
| 16488 FixedTypedArrayTestHelper<i::FixedInt8Array, i::INT8_ELEMENTS, int8_t>( |
| 16489 v8::kExternalByteArray, |
| 16490 -0x80, 0x7F); |
| 16491 } |
| 16492 |
| 16493 |
| 16494 THREADED_TEST(FixedUint16Array) { |
| 16495 FixedTypedArrayTestHelper<i::FixedUint16Array, i::UINT16_ELEMENTS, uint16_t>( |
| 16496 v8::kExternalUnsignedShortArray, |
| 16497 0x0, 0xFFFF); |
| 16498 } |
| 16499 |
| 16500 |
| 16501 THREADED_TEST(FixedInt16Array) { |
| 16502 FixedTypedArrayTestHelper<i::FixedInt16Array, i::INT16_ELEMENTS, int16_t>( |
| 16503 v8::kExternalShortArray, |
| 16504 -0x8000, 0x7FFF); |
| 16505 } |
| 16506 |
| 16507 |
| 16508 THREADED_TEST(FixedUint32Array) { |
| 16509 FixedTypedArrayTestHelper<i::FixedUint32Array, i::UINT32_ELEMENTS, uint32_t>( |
| 16510 v8::kExternalUnsignedIntArray, |
| 16511 0x0, 0xFFFFFFFF); |
| 16512 } |
| 16513 |
| 16514 |
| 16515 THREADED_TEST(FixedInt32Array) { |
| 16516 FixedTypedArrayTestHelper<i::FixedInt32Array, i::INT32_ELEMENTS, int32_t>( |
| 16517 v8::kExternalIntArray, |
| 16518 -0x80000000, 0x7FFFFFFF); |
| 16519 } |
| 16520 |
| 16521 |
| 16522 THREADED_TEST(FixedFloat32Array) { |
| 16523 FixedTypedArrayTestHelper<i::FixedFloat32Array, i::FLOAT32_ELEMENTS, float>( |
| 16524 v8::kExternalFloatArray, |
| 16525 -500, 500); |
| 16526 } |
| 16527 |
| 16528 |
| 16529 THREADED_TEST(FixedFloat64Array) { |
| 16530 FixedTypedArrayTestHelper<i::FixedFloat64Array, i::FLOAT64_ELEMENTS, float>( |
| 16531 v8::kExternalDoubleArray, |
| 16532 -500, 500); |
| 16533 } |
| 16534 |
| 16535 |
16430 template <class ExternalArrayClass, class ElementType> | 16536 template <class ExternalArrayClass, class ElementType> |
16431 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, | 16537 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, |
16432 int64_t low, | 16538 int64_t low, |
16433 int64_t high) { | 16539 int64_t high) { |
16434 LocalContext context; | 16540 LocalContext context; |
16435 i::Isolate* isolate = CcTest::i_isolate(); | 16541 i::Isolate* isolate = CcTest::i_isolate(); |
16436 i::Factory* factory = isolate->factory(); | 16542 i::Factory* factory = isolate->factory(); |
16437 v8::HandleScope scope(context->GetIsolate()); | 16543 v8::HandleScope scope(context->GetIsolate()); |
16438 const int kElementCount = 40; | 16544 const int kElementCount = 40; |
16439 int element_size = ExternalArrayElementSize(array_type); | 16545 int element_size = ExternalArrayElementSize(array_type); |
(...skipping 5208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21648 } | 21754 } |
21649 for (int i = 0; i < runs; i++) { | 21755 for (int i = 0; i < runs; i++) { |
21650 Local<String> expected; | 21756 Local<String> expected; |
21651 if (i != 0) { | 21757 if (i != 0) { |
21652 CHECK_EQ(v8_str("escape value"), values[i]); | 21758 CHECK_EQ(v8_str("escape value"), values[i]); |
21653 } else { | 21759 } else { |
21654 CHECK(values[i].IsEmpty()); | 21760 CHECK(values[i].IsEmpty()); |
21655 } | 21761 } |
21656 } | 21762 } |
21657 } | 21763 } |
OLD | NEW |