Chromium Code Reviews| 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 2553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2564 } | 2564 } |
| 2565 | 2565 |
| 2566 | 2566 |
| 2567 bool Value::IsArrayBuffer() const { | 2567 bool Value::IsArrayBuffer() const { |
| 2568 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()")) | 2568 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()")) |
| 2569 return false; | 2569 return false; |
| 2570 return Utils::OpenHandle(this)->IsJSArrayBuffer(); | 2570 return Utils::OpenHandle(this)->IsJSArrayBuffer(); |
| 2571 } | 2571 } |
| 2572 | 2572 |
| 2573 | 2573 |
| 2574 bool Value::IsDataView() const { | |
| 2575 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsDataView()")) | |
| 2576 return false; | |
| 2577 return Utils::OpenHandle(this)->IsJSDataView(); | |
| 2578 } | |
| 2579 | |
| 2580 | |
| 2574 bool Value::IsTypedArray() const { | 2581 bool Value::IsTypedArray() const { |
| 2575 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()")) | 2582 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsArrayBuffer()")) |
| 2576 return false; | 2583 return false; |
| 2577 return Utils::OpenHandle(this)->IsJSTypedArray(); | 2584 return Utils::OpenHandle(this)->IsJSTypedArray(); |
| 2578 } | 2585 } |
| 2579 | 2586 |
| 2580 | 2587 |
| 2581 #define TYPED_ARRAY_LIST(F) \ | 2588 #define TYPED_ARRAY_LIST(F) \ |
| 2582 F(Uint8Array, kExternalUnsignedByteArray) \ | 2589 F(Uint8Array, kExternalUnsignedByteArray) \ |
| 2583 F(Int8Array, kExternalByteArray) \ | 2590 F(Int8Array, kExternalByteArray) \ |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2943 | 2950 |
| 2944 void v8::ArrayBuffer::CheckCast(Value* that) { | 2951 void v8::ArrayBuffer::CheckCast(Value* that) { |
| 2945 if (IsDeadCheck(i::Isolate::Current(), "v8::ArrayBuffer::Cast()")) return; | 2952 if (IsDeadCheck(i::Isolate::Current(), "v8::ArrayBuffer::Cast()")) return; |
| 2946 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 2953 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2947 ApiCheck(obj->IsJSArrayBuffer(), | 2954 ApiCheck(obj->IsJSArrayBuffer(), |
| 2948 "v8::ArrayBuffer::Cast()", | 2955 "v8::ArrayBuffer::Cast()", |
| 2949 "Could not convert to ArrayBuffer"); | 2956 "Could not convert to ArrayBuffer"); |
| 2950 } | 2957 } |
| 2951 | 2958 |
| 2952 | 2959 |
| 2960 void v8::DataView::CheckCast(Value* that) { | |
| 2961 if (IsDeadCheck(i::Isolate::Current(), "v8::DataView::Cast()")) return; | |
| 2962 i::Handle<i::Object> obj = Utils::OpenHandle(that); | |
| 2963 ApiCheck(obj->IsJSDataView(), | |
| 2964 "v8::DataView::Cast()", | |
| 2965 "Could not convert to DataView"); | |
| 2966 } | |
| 2967 | |
| 2968 | |
| 2953 void v8::TypedArray::CheckCast(Value* that) { | 2969 void v8::TypedArray::CheckCast(Value* that) { |
| 2954 if (IsDeadCheck(i::Isolate::Current(), "v8::TypedArray::Cast()")) return; | 2970 if (IsDeadCheck(i::Isolate::Current(), "v8::TypedArray::Cast()")) return; |
| 2955 i::Handle<i::Object> obj = Utils::OpenHandle(that); | 2971 i::Handle<i::Object> obj = Utils::OpenHandle(that); |
| 2956 ApiCheck(obj->IsJSTypedArray(), | 2972 ApiCheck(obj->IsJSTypedArray(), |
| 2957 "v8::TypedArray::Cast()", | 2973 "v8::TypedArray::Cast()", |
| 2958 "Could not convert to TypedArray"); | 2974 "Could not convert to TypedArray"); |
| 2959 } | 2975 } |
| 2960 | 2976 |
| 2961 | 2977 |
| 2962 #define CHECK_TYPED_ARRAY_CAST(ApiClass, typeConst) \ | 2978 #define CHECK_TYPED_ARRAY_CAST(ApiClass, typeConst) \ |
| (...skipping 3094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6057 EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(void*, size_t)"); | 6073 EnsureInitializedForIsolate(isolate, "v8::ArrayBuffer::New(void*, size_t)"); |
| 6058 LOG_API(isolate, "v8::ArrayBuffer::New(void*, size_t)"); | 6074 LOG_API(isolate, "v8::ArrayBuffer::New(void*, size_t)"); |
| 6059 ENTER_V8(isolate); | 6075 ENTER_V8(isolate); |
| 6060 i::Handle<i::JSArrayBuffer> obj = | 6076 i::Handle<i::JSArrayBuffer> obj = |
| 6061 isolate->factory()->NewJSArrayBuffer(); | 6077 isolate->factory()->NewJSArrayBuffer(); |
| 6062 i::Runtime::SetupArrayBuffer(isolate, obj, true, data, byte_length); | 6078 i::Runtime::SetupArrayBuffer(isolate, obj, true, data, byte_length); |
| 6063 return Utils::ToLocal(obj); | 6079 return Utils::ToLocal(obj); |
| 6064 } | 6080 } |
| 6065 | 6081 |
| 6066 | 6082 |
| 6083 Local<DataView> v8::DataView::New(Handle<ArrayBuffer> array_buffer, | |
| 6084 size_t byte_offset, | |
| 6085 size_t byte_length) { | |
| 6086 i::Isolate* isolate = i::Isolate::Current(); | |
| 6087 i::Handle<i::JSDataView> obj = | |
| 6088 isolate->factory()->NewJSDataView(); | |
| 6089 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); | |
| 6090 ASSERT(byte_offset + byte_length <= | |
| 6091 static_cast<size_t>(buffer->byte_length()->Number())); | |
| 6092 obj->set_buffer(*buffer); | |
| 6093 i::Handle<i::Object> byte_offset_object = isolate->factory()->NewNumber( | |
| 6094 static_cast<double>(byte_offset)); | |
| 6095 obj->set_byte_offset(*byte_offset_object); | |
| 6096 i::Handle<i::Object> byte_length_object = isolate->factory()->NewNumber( | |
| 6097 static_cast<double>(byte_length)); | |
| 6098 obj->set_byte_length(*byte_length_object); | |
| 6099 i::Handle<i::ExternalArray> elements = | |
|
Dmitry Lomov (no reviews)
2013/06/03 13:09:04
DataView is not a external array, so everything he
bnoordhuis
2013/06/03 13:48:12
Sorry, that's a left-over from my initial attempt.
| |
| 6100 isolate->factory()->NewExternalArray( | |
| 6101 static_cast<int>(byte_length), | |
| 6102 kExternalUnsignedByteArray, | |
| 6103 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); | |
| 6104 i::Handle<i::Map> map = | |
| 6105 isolate->factory()->GetElementsTransitionMap( | |
| 6106 obj, i::EXTERNAL_UNSIGNED_BYTE_ELEMENTS); | |
| 6107 obj->set_map(*map); | |
| 6108 obj->set_elements(*elements); | |
| 6109 return Utils::ToLocal(obj); | |
| 6110 } | |
| 6111 | |
| 6112 | |
| 6113 Local<ArrayBuffer> v8::DataView::Buffer() { | |
| 6114 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6115 if (IsDeadCheck(isolate, "v8::DataView::Buffer()")) | |
| 6116 return Local<ArrayBuffer>(); | |
| 6117 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6118 ASSERT(obj->buffer()->IsJSArrayBuffer()); | |
| 6119 i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer())); | |
| 6120 return Utils::ToLocal(buffer); | |
| 6121 } | |
| 6122 | |
| 6123 | |
| 6124 size_t v8::DataView::ByteOffset() const { | |
| 6125 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6126 if (IsDeadCheck(isolate, "v8::DataView::ByteOffset()")) return 0; | |
| 6127 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6128 return static_cast<size_t>(obj->byte_offset()->Number()); | |
| 6129 } | |
| 6130 | |
| 6131 | |
| 6132 size_t v8::DataView::ByteLength() const { | |
| 6133 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6134 if (IsDeadCheck(isolate, "v8::DataView::ByteLength()")) return 0; | |
| 6135 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6136 return static_cast<size_t>(obj->byte_length()->Number()); | |
| 6137 } | |
| 6138 | |
| 6139 | |
| 6140 void* v8::DataView::Data() const { | |
| 6141 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6142 if (IsDeadCheck(isolate, "v8::DataView::BaseAddress()")) return NULL; | |
| 6143 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6144 i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer())); | |
| 6145 void* buffer_data = buffer->backing_store(); | |
| 6146 size_t byte_offset = static_cast<size_t>(obj->byte_offset()->Number()); | |
| 6147 return static_cast<uint8_t*>(buffer_data) + byte_offset; | |
| 6148 } | |
| 6149 | |
| 6150 | |
| 6151 int8_t v8::DataView::GetInt8(size_t byte_offset) const { | |
| 6152 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6153 if (IsDeadCheck(isolate, "v8::DataView::GetInt8")) return 0; | |
| 6154 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6155 return obj->Get<int8_t>(byte_offset); | |
| 6156 } | |
| 6157 | |
| 6158 | |
| 6159 uint8_t v8::DataView::GetUint8(size_t byte_offset) const { | |
| 6160 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6161 if (IsDeadCheck(isolate, "v8::DataView::GetUint8")) return 0; | |
| 6162 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6163 return obj->Get<uint8_t>(byte_offset); | |
| 6164 } | |
| 6165 | |
| 6166 | |
| 6167 int16_t v8::DataView::GetInt16(size_t byte_offset, bool little_endian) const { | |
| 6168 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6169 if (IsDeadCheck(isolate, "v8::DataView::GetInt16")) return 0; | |
| 6170 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6171 return obj->Get<int16_t>(byte_offset, little_endian); | |
| 6172 } | |
| 6173 | |
| 6174 | |
| 6175 uint16_t v8::DataView::GetUint16(size_t byte_offset, bool little_endian) const { | |
| 6176 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6177 if (IsDeadCheck(isolate, "v8::DataView::GetUint16")) return 0; | |
| 6178 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6179 return obj->Get<uint16_t>(byte_offset, little_endian); | |
| 6180 } | |
| 6181 | |
| 6182 | |
| 6183 int32_t v8::DataView::GetInt32(size_t byte_offset, bool little_endian) const { | |
| 6184 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6185 if (IsDeadCheck(isolate, "v8::DataView::GetInt32")) return 0; | |
| 6186 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6187 return obj->Get<int32_t>(byte_offset, little_endian); | |
| 6188 } | |
| 6189 | |
| 6190 | |
| 6191 uint32_t v8::DataView::GetUint32(size_t byte_offset, bool little_endian) const { | |
| 6192 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6193 if (IsDeadCheck(isolate, "v8::DataView::GetUint32")) return 0; | |
| 6194 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6195 return obj->Get<uint32_t>(byte_offset, little_endian); | |
| 6196 } | |
| 6197 | |
| 6198 | |
| 6199 float v8::DataView::GetFloat32(size_t byte_offset, bool little_endian) const { | |
| 6200 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6201 if (IsDeadCheck(isolate, "v8::DataView::GetFloat32")) return 0; | |
| 6202 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6203 return obj->Get<float>(byte_offset, little_endian); | |
| 6204 } | |
| 6205 | |
| 6206 | |
| 6207 double v8::DataView::GetFloat64(size_t byte_offset, bool little_endian) const { | |
| 6208 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6209 if (IsDeadCheck(isolate, "v8::DataView::GetFloat64")) return 0; | |
| 6210 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6211 return obj->Get<double>(byte_offset, little_endian); | |
| 6212 } | |
| 6213 | |
| 6214 | |
| 6215 void v8::DataView::SetInt8(size_t byte_offset, int8_t value) { | |
| 6216 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6217 if (IsDeadCheck(isolate, "v8::DataView::SetInt8")) return; | |
| 6218 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6219 obj->Set(byte_offset, value); | |
| 6220 } | |
| 6221 | |
| 6222 | |
| 6223 void v8::DataView::SetUint8(size_t byte_offset, uint8_t value) { | |
| 6224 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6225 if (IsDeadCheck(isolate, "v8::DataView::SetUint8")) return; | |
| 6226 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6227 obj->Set(byte_offset, value); | |
| 6228 } | |
| 6229 | |
| 6230 | |
| 6231 void v8::DataView::SetInt16(size_t byte_offset, | |
| 6232 int16_t value, | |
| 6233 bool little_endian) { | |
| 6234 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6235 if (IsDeadCheck(isolate, "v8::DataView::SetInt16")) return; | |
| 6236 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6237 obj->Set(byte_offset, value, little_endian); | |
| 6238 } | |
| 6239 | |
| 6240 | |
| 6241 void v8::DataView::SetUint16(size_t byte_offset, | |
| 6242 uint16_t value, | |
| 6243 bool little_endian) { | |
| 6244 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6245 if (IsDeadCheck(isolate, "v8::DataView::SetUint16")) return; | |
| 6246 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6247 obj->Set(byte_offset, value, little_endian); | |
| 6248 } | |
| 6249 | |
| 6250 | |
| 6251 void v8::DataView::SetInt32(size_t byte_offset, | |
| 6252 int32_t value, | |
| 6253 bool little_endian) { | |
| 6254 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6255 if (IsDeadCheck(isolate, "v8::DataView::SetInt32")) return; | |
| 6256 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6257 obj->Set(byte_offset, value, little_endian); | |
| 6258 } | |
| 6259 | |
| 6260 | |
| 6261 void v8::DataView::SetUint32(size_t byte_offset, | |
| 6262 uint32_t value, | |
| 6263 bool little_endian) { | |
| 6264 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6265 if (IsDeadCheck(isolate, "v8::DataView::SetUint32")) return; | |
| 6266 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6267 obj->Set(byte_offset, value, little_endian); | |
| 6268 } | |
| 6269 | |
| 6270 | |
| 6271 void v8::DataView::SetFloat32(size_t byte_offset, | |
| 6272 float value, | |
| 6273 bool little_endian) { | |
| 6274 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6275 if (IsDeadCheck(isolate, "v8::DataView::SetFloat32")) return; | |
| 6276 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6277 obj->Set(byte_offset, value, little_endian); | |
| 6278 } | |
| 6279 | |
| 6280 | |
| 6281 void v8::DataView::SetFloat64(size_t byte_offset, | |
| 6282 double value, | |
| 6283 bool little_endian) { | |
| 6284 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
| 6285 if (IsDeadCheck(isolate, "v8::DataView::SetFloat64")) return; | |
| 6286 i::Handle<i::JSDataView> obj = Utils::OpenHandle(this); | |
| 6287 obj->Set(byte_offset, value, little_endian); | |
| 6288 } | |
| 6289 | |
| 6290 | |
| 6067 Local<ArrayBuffer> v8::TypedArray::Buffer() { | 6291 Local<ArrayBuffer> v8::TypedArray::Buffer() { |
| 6068 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 6292 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 6069 if (IsDeadCheck(isolate, "v8::TypedArray::Buffer()")) | 6293 if (IsDeadCheck(isolate, "v8::TypedArray::Buffer()")) |
| 6070 return Local<ArrayBuffer>(); | 6294 return Local<ArrayBuffer>(); |
| 6071 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this); | 6295 i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this); |
| 6072 ASSERT(obj->buffer()->IsJSArrayBuffer()); | 6296 ASSERT(obj->buffer()->IsJSArrayBuffer()); |
| 6073 i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer())); | 6297 i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(obj->buffer())); |
| 6074 return Utils::ToLocal(buffer); | 6298 return Utils::ToLocal(buffer); |
| 6075 } | 6299 } |
| 6076 | 6300 |
| (...skipping 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7857 | 8081 |
| 7858 v->VisitPointers(blocks_.first(), first_block_limit_); | 8082 v->VisitPointers(blocks_.first(), first_block_limit_); |
| 7859 | 8083 |
| 7860 for (int i = 1; i < blocks_.length(); i++) { | 8084 for (int i = 1; i < blocks_.length(); i++) { |
| 7861 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); | 8085 v->VisitPointers(blocks_[i], &blocks_[i][kHandleBlockSize]); |
| 7862 } | 8086 } |
| 7863 } | 8087 } |
| 7864 | 8088 |
| 7865 | 8089 |
| 7866 } } // namespace v8::internal | 8090 } } // namespace v8::internal |
| OLD | NEW |