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

Side by Side Diff: include/v8.h

Issue 15943002: v8 typed arrays: add DataView type (Closed)
Patch Set: v8 typed arrays: add DataView type, v2 Created 7 years, 6 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 | « no previous file | src/api.h » ('j') | src/api.cc » ('J')
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 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 bool IsRegExp() const; 1395 bool IsRegExp() const;
1396 1396
1397 1397
1398 /** 1398 /**
1399 * Returns true if this value is an ArrayBuffer. 1399 * Returns true if this value is an ArrayBuffer.
1400 * This is an experimental feature. 1400 * This is an experimental feature.
1401 */ 1401 */
1402 bool IsArrayBuffer() const; 1402 bool IsArrayBuffer() const;
1403 1403
1404 /** 1404 /**
1405 * Returns true if this value is a DataView.
1406 * This is an experimental feature.
1407 */
1408 bool IsDataView() const;
1409
1410 /**
1405 * Returns true if this value is one of TypedArrays. 1411 * Returns true if this value is one of TypedArrays.
1406 * This is an experimental feature. 1412 * This is an experimental feature.
1407 */ 1413 */
1408 bool IsTypedArray() const; 1414 bool IsTypedArray() const;
1409 1415
1410 /** 1416 /**
1411 * Returns true if this value is an Uint8Array. 1417 * Returns true if this value is an Uint8Array.
1412 * This is an experimental feature. 1418 * This is an experimental feature.
1413 */ 1419 */
1414 bool IsUint8Array() const; 1420 bool IsUint8Array() const;
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
2448 2454
2449 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; 2455 static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
2450 2456
2451 private: 2457 private:
2452 ArrayBuffer(); 2458 ArrayBuffer();
2453 static void CheckCast(Value* obj); 2459 static void CheckCast(Value* obj);
2454 }; 2460 };
2455 2461
2456 2462
2457 /** 2463 /**
2464 * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
2465 * This API is experimental and may change significantly.
2466 */
2467 class V8EXPORT DataView : public Object {
2468 public:
2469 /**
2470 * Returns underlying ArrayBuffer.
2471 */
2472 Local<ArrayBuffer> Buffer();
2473
2474 /**
2475 * Byte offset in |Buffer|
2476 */
2477 size_t ByteOffset() const;
2478
2479 /**
2480 * Size of data view in bytes.
2481 */
2482 size_t ByteLength() const;
2483
2484 /**
2485 * Raw pointer to the buffer view data.
2486 */
2487 void* Data() const;
2488
2489 static Local<DataView> New(Handle<ArrayBuffer> array_buffer,
2490 size_t byte_offset,
2491 size_t byte_length);
2492 V8_INLINE(static DataView* Cast(Value* obj));
2493
2494 /**
2495 * Return the value at |byte_offset| or 0 if |byte_offset| is out of range.
2496 */
2497 int8_t GetInt8(size_t byte_offset) const;
2498
2499 /**
2500 * Return the value at |byte_offset| or 0 if |byte_offset| is out of range.
2501 */
2502 uint8_t GetUint8(size_t byte_offset) const;
2503
2504 /**
2505 * Return the value at |byte_offset| or 0 if |byte_offset| is out of range.
2506 */
2507 int16_t GetInt16(size_t byte_offset, bool little_endian = false) const;
2508
2509 /**
2510 * Return the value at |byte_offset| or 0 if |byte_offset| is out of range.
2511 * Reads a big-endian value unless |little_endian| is true.
2512 */
2513 uint16_t GetUint16(size_t byte_offset, bool little_endian = false) const;
2514
2515 /**
2516 * Return the value at |byte_offset| or 0 if |byte_offset| is out of range.
2517 * Reads a big-endian value unless |little_endian| is true.
2518 */
2519 int32_t GetInt32(size_t byte_offset, bool little_endian = false) const;
2520
2521 /**
2522 * Return the value at |byte_offset| or 0 if |byte_offset| is out of range.
2523 * Reads a big-endian value unless |little_endian| is true.
2524 */
2525 uint32_t GetUint32(size_t byte_offset, bool little_endian = false) const;
2526
2527 /**
2528 * Return the value at |byte_offset| or 0 if |byte_offset| is out of range.
2529 * Reads a big-endian value unless |little_endian| is true.
2530 */
2531 float GetFloat32(size_t byte_offset, bool little_endian = false) const;
2532
2533 /**
2534 * Return the value at |byte_offset| or 0 if |byte_offset| is out of range.
2535 * Reads a big-endian value unless |little_endian| is true.
2536 */
2537 double GetFloat64(size_t byte_offset, bool little_endian = false) const;
2538
2539 /**
2540 * Set the value at |byte_offset| to |value|. Does nothing if |byte_offset|
2541 * is out of range.
2542 */
2543 void SetInt8(size_t byte_offset, int8_t value);
2544
2545 /**
2546 * Set the value at |byte_offset| to |value|. Does nothing if |byte_offset|
2547 * is out of range.
2548 */
2549 void SetUint8(size_t byte_offset, uint8_t value);
2550
2551 /**
2552 * Set the value at |byte_offset| to |value|. Does nothing if |byte_offset|
2553 * is out of range. Writes a big-endian value unless |little_endian| is true.
2554 */
2555 void SetInt16(size_t byte_offset, int16_t value, bool little_endian = false);
2556
2557 /**
2558 * Set the value at |byte_offset| to |value|. Does nothing if |byte_offset|
2559 * is out of range.
2560 */
2561 void SetUint16(size_t byte_offset,
2562 uint16_t value,
2563 bool little_endian = false);
2564
2565 /**
2566 * Set the value at |byte_offset| to |value|. Does nothing if |byte_offset|
2567 * is out of range. Writes a big-endian value unless |little_endian| is true.
2568 */
2569 void SetInt32(size_t byte_offset, int32_t value, bool little_endian = false);
2570
2571 /**
2572 * Set the value at |byte_offset| to |value|. Does nothing if |byte_offset|
2573 * is out of range. Writes a big-endian value unless |little_endian| is true.
2574 */
2575 void SetUint32(size_t byte_offset,
2576 uint32_t value,
2577 bool little_endian = false);
2578
2579 /**
2580 * Set the value at |byte_offset| to |value|. Does nothing if |byte_offset|
2581 * is out of range. Writes a big-endian value unless |little_endian| is true.
2582 */
2583 void SetFloat32(size_t byte_offset, float value, bool little_endian = false);
2584
2585 /**
2586 * Set the value at |byte_offset| to |value|. Does nothing if |byte_offset|
2587 * is out of range. Writes a big-endian value unless |little_endian| is true.
2588 */
2589 void SetFloat64(size_t byte_offset, double value, bool little_endian = false);
2590
2591 private:
2592 DataView();
2593 static void CheckCast(Value* obj);
2594 };
2595
2596
2597 /**
2458 * A base class for an instance of TypedArray series of constructors 2598 * A base class for an instance of TypedArray series of constructors
2459 * (ES6 draft 15.13.6). 2599 * (ES6 draft 15.13.6).
2460 * This API is experimental and may change significantly. 2600 * This API is experimental and may change significantly.
2461 */ 2601 */
2462 class V8EXPORT TypedArray : public Object { 2602 class V8EXPORT TypedArray : public Object {
2463 public: 2603 public:
2464 /** 2604 /**
2465 * Returns underlying ArrayBuffer. 2605 * Returns underlying ArrayBuffer.
2466 */ 2606 */
2467 Local<ArrayBuffer> Buffer(); 2607 Local<ArrayBuffer> Buffer();
(...skipping 2802 matching lines...) Expand 10 before | Expand all | Expand 10 after
5270 // the implementation of v8. 5410 // the implementation of v8.
5271 static const int kHeapObjectMapOffset = 0; 5411 static const int kHeapObjectMapOffset = 0;
5272 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; 5412 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
5273 static const int kStringResourceOffset = 3 * kApiPointerSize; 5413 static const int kStringResourceOffset = 3 * kApiPointerSize;
5274 5414
5275 static const int kOddballKindOffset = 3 * kApiPointerSize; 5415 static const int kOddballKindOffset = 3 * kApiPointerSize;
5276 static const int kForeignAddressOffset = kApiPointerSize; 5416 static const int kForeignAddressOffset = kApiPointerSize;
5277 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; 5417 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
5278 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; 5418 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
5279 static const int kContextHeaderSize = 2 * kApiPointerSize; 5419 static const int kContextHeaderSize = 2 * kApiPointerSize;
5280 static const int kContextEmbedderDataIndex = 64; 5420 static const int kContextEmbedderDataIndex = 65;
5281 static const int kFullStringRepresentationMask = 0x07; 5421 static const int kFullStringRepresentationMask = 0x07;
5282 static const int kStringEncodingMask = 0x4; 5422 static const int kStringEncodingMask = 0x4;
5283 static const int kExternalTwoByteRepresentationTag = 0x02; 5423 static const int kExternalTwoByteRepresentationTag = 0x02;
5284 static const int kExternalAsciiRepresentationTag = 0x06; 5424 static const int kExternalAsciiRepresentationTag = 0x06;
5285 5425
5286 static const int kIsolateStateOffset = 0; 5426 static const int kIsolateStateOffset = 0;
5287 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; 5427 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize;
5288 static const int kIsolateRootsOffset = 3 * kApiPointerSize; 5428 static const int kIsolateRootsOffset = 3 * kApiPointerSize;
5289 static const int kUndefinedValueRootIndex = 5; 5429 static const int kUndefinedValueRootIndex = 5;
5290 static const int kNullValueRootIndex = 7; 5430 static const int kNullValueRootIndex = 7;
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
6095 6235
6096 6236
6097 ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) { 6237 ArrayBuffer* ArrayBuffer::Cast(v8::Value* value) {
6098 #ifdef V8_ENABLE_CHECKS 6238 #ifdef V8_ENABLE_CHECKS
6099 CheckCast(value); 6239 CheckCast(value);
6100 #endif 6240 #endif
6101 return static_cast<ArrayBuffer*>(value); 6241 return static_cast<ArrayBuffer*>(value);
6102 } 6242 }
6103 6243
6104 6244
6245 DataView* DataView::Cast(v8::Value* value) {
6246 #ifdef V8_ENABLE_CHECKS
6247 CheckCast(value);
6248 #endif
6249 return static_cast<DataView*>(value);
6250 }
6251
6252
6105 TypedArray* TypedArray::Cast(v8::Value* value) { 6253 TypedArray* TypedArray::Cast(v8::Value* value) {
6106 #ifdef V8_ENABLE_CHECKS 6254 #ifdef V8_ENABLE_CHECKS
6107 CheckCast(value); 6255 CheckCast(value);
6108 #endif 6256 #endif
6109 return static_cast<TypedArray*>(value); 6257 return static_cast<TypedArray*>(value);
6110 } 6258 }
6111 6259
6112 6260
6113 Uint8Array* Uint8Array::Cast(v8::Value* value) { 6261 Uint8Array* Uint8Array::Cast(v8::Value* value) {
6114 #ifdef V8_ENABLE_CHECKS 6262 #ifdef V8_ENABLE_CHECKS
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
6303 6451
6304 6452
6305 } // namespace v8 6453 } // namespace v8
6306 6454
6307 6455
6308 #undef V8EXPORT 6456 #undef V8EXPORT
6309 #undef TYPE_CHECK 6457 #undef TYPE_CHECK
6310 6458
6311 6459
6312 #endif // V8_H_ 6460 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.h » ('j') | src/api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698