OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 506 } |
507 | 507 |
508 Dart_Handle args[2] = { result, asList }; | 508 Dart_Handle args[2] = { result, asList }; |
509 DartUtilities::invokeUtilsMethod("populateMap", 2, args); | 509 DartUtilities::invokeUtilsMethod("populateMap", 2, args); |
510 return result; | 510 return result; |
511 } | 511 } |
512 | 512 |
513 v8::Handle<v8::Value> V8Converter::arrayBufferToV8(Dart_Handle value, Dart_Handl
e& exception) | 513 v8::Handle<v8::Value> V8Converter::arrayBufferToV8(Dart_Handle value, Dart_Handl
e& exception) |
514 { | 514 { |
515 ScriptState* state = DartUtilities::v8ScriptStateForCurrentIsolate(); | 515 ScriptState* state = DartUtilities::v8ScriptStateForCurrentIsolate(); |
516 return blink::toV8(DartUtilities::dartToExternalizedArrayBuffer(value, excep
tion).get(), state->context()->Global(), state->isolate()); | 516 RefPtr<DOMArrayBuffer> arrayBuffer = DOMArrayBuffer::create(DartUtilities::d
artToExternalizedArrayBuffer(value, exception)); |
| 517 v8::Handle<v8::Object> global = state->context()->Global(); |
| 518 v8::Isolate* v8Isolate = state->isolate(); |
| 519 return blink::toV8(arrayBuffer.get(), global, v8Isolate); |
517 } | 520 } |
518 | 521 |
519 Dart_Handle V8Converter::arrayBufferToDart(v8::Handle<v8::Object> object, Dart_H
andle& exception) | 522 Dart_Handle V8Converter::arrayBufferToDart(v8::Handle<v8::Object> object, Dart_H
andle& exception) |
520 { | 523 { |
521 return DartUtilities::arrayBufferToDart(V8ArrayBuffer::toImpl(object)->buffe
r()); | 524 return DartUtilities::arrayBufferToDart(V8ArrayBuffer::toImpl(object)->buffe
r()); |
522 } | 525 } |
523 | 526 |
524 v8::Handle<v8::Value> V8Converter::arrayBufferViewToV8(Dart_Handle value, Dart_H
andle& exception) | 527 v8::Handle<v8::Value> V8Converter::arrayBufferViewToV8(Dart_Handle value, Dart_H
andle& exception) |
525 { | 528 { |
526 RefPtr<ArrayBufferView> view = DartUtilities::dartToExternalizedArrayBufferV
iew(value, exception); | 529 RefPtr<ArrayBufferView> view = DartUtilities::dartToExternalizedArrayBufferV
iew(value, exception); |
527 ScriptState* state = DartUtilities::v8ScriptStateForCurrentIsolate(); | 530 ScriptState* state = DartUtilities::v8ScriptStateForCurrentIsolate(); |
| 531 unsigned byteOffset = view->byteOffset(); |
| 532 // this is copied from ScriptValueSerializer. |
| 533 int elementByteSize = 1; |
| 534 ArrayBuffer* data = view->buffer().get(); |
528 | 535 |
529 switch (view->type()) { | 536 switch (view->type()) { |
530 case ArrayBufferView::TypeInt8: | 537 case ArrayBufferView::TypeInt8: |
531 return blink::toV8(static_cast<Int8Array*>(view.get()), state->context()
->Global(), state->isolate()); | 538 elementByteSize = sizeof(DOMInt8Array::ValueType); |
| 539 break; |
532 case ArrayBufferView::TypeUint8: | 540 case ArrayBufferView::TypeUint8: |
533 return blink::toV8(static_cast<Uint8Array*>(view.get()), state->context(
)->Global(), state->isolate()); | 541 elementByteSize = sizeof(DOMUint8Array::ValueType); |
| 542 break; |
534 case ArrayBufferView::TypeUint8Clamped: | 543 case ArrayBufferView::TypeUint8Clamped: |
535 return blink::toV8(static_cast<Uint8ClampedArray*>(view.get()), state->c
ontext()->Global(), state->isolate()); | 544 elementByteSize = sizeof(DOMUint8ClampedArray::ValueType); |
| 545 break; |
536 case ArrayBufferView::TypeInt16: | 546 case ArrayBufferView::TypeInt16: |
537 return blink::toV8(static_cast<Int16Array*>(view.get()), state->context(
)->Global(), state->isolate()); | 547 elementByteSize = sizeof(DOMInt16Array::ValueType); |
| 548 break; |
538 case ArrayBufferView::TypeUint16: | 549 case ArrayBufferView::TypeUint16: |
539 return blink::toV8(static_cast<Uint16Array*>(view.get()), state->context
()->Global(), state->isolate()); | 550 elementByteSize = sizeof(DOMUint16Array::ValueType); |
| 551 break; |
540 case ArrayBufferView::TypeInt32: | 552 case ArrayBufferView::TypeInt32: |
541 return blink::toV8(static_cast<Int32Array*>(view.get()), state->context(
)->Global(), state->isolate()); | 553 elementByteSize = sizeof(DOMInt32Array::ValueType); |
| 554 break; |
542 case ArrayBufferView::TypeUint32: | 555 case ArrayBufferView::TypeUint32: |
543 return blink::toV8(static_cast<Uint32Array*>(view.get()), state->context
()->Global(), state->isolate()); | 556 elementByteSize = sizeof(DOMUint32Array::ValueType); |
| 557 break; |
544 case ArrayBufferView::TypeFloat32: | 558 case ArrayBufferView::TypeFloat32: |
545 return blink::toV8(static_cast<Float32Array*>(view.get()), state->contex
t()->Global(), state->isolate()); | 559 elementByteSize = sizeof(DOMFloat32Array::ValueType); |
| 560 break; |
546 case ArrayBufferView::TypeFloat64: | 561 case ArrayBufferView::TypeFloat64: |
547 return blink::toV8(static_cast<Float64Array*>(view.get()), state->contex
t()->Global(), state->isolate()); | 562 elementByteSize = sizeof(DOMFloat64Array::ValueType); |
| 563 break; |
| 564 case ArrayBufferView::TypeDataView: |
| 565 elementByteSize = sizeof(DOMDataView::ValueType); |
| 566 break; |
| 567 default: |
| 568 ASSERT_NOT_REACHED(); |
| 569 } |
| 570 unsigned numElements = view->byteLength() / elementByteSize; |
| 571 |
| 572 switch (view->type()) { |
| 573 case ArrayBufferView::TypeInt8: |
| 574 return blink::toV8(DOMInt8Array::create(data, byteOffset, numElements),
state->context()->Global(), state->isolate()); |
| 575 case ArrayBufferView::TypeUint8: |
| 576 return blink::toV8(DOMUint8Array::create(data, byteOffset, numElements),
state->context()->Global(), state->isolate()); |
| 577 case ArrayBufferView::TypeUint8Clamped: |
| 578 return blink::toV8(DOMUint8ClampedArray::create(data, byteOffset, numEle
ments), state->context()->Global(), state->isolate()); |
| 579 case ArrayBufferView::TypeInt16: |
| 580 return blink::toV8(DOMInt16Array::create(data, byteOffset, numElements),
state->context()->Global(), state->isolate()); |
| 581 case ArrayBufferView::TypeUint16: |
| 582 return blink::toV8(DOMUint16Array::create(data, byteOffset, numElements)
, state->context()->Global(), state->isolate()); |
| 583 case ArrayBufferView::TypeInt32: |
| 584 return blink::toV8(DOMInt32Array::create(data, byteOffset, numElements),
state->context()->Global(), state->isolate()); |
| 585 case ArrayBufferView::TypeUint32: |
| 586 return blink::toV8(DOMUint32Array::create(data, byteOffset, numElements)
, state->context()->Global(), state->isolate()); |
| 587 case ArrayBufferView::TypeFloat32: |
| 588 return blink::toV8(DOMFloat32Array::create(data, byteOffset, numElements
), state->context()->Global(), state->isolate()); |
| 589 case ArrayBufferView::TypeFloat64: |
| 590 return blink::toV8(DOMFloat64Array::create(data, byteOffset, numElements
), state->context()->Global(), state->isolate()); |
548 case ArrayBufferView::TypeDataView: | 591 case ArrayBufferView::TypeDataView: |
549 { | 592 { |
| 593 RefPtr<DOMArrayBufferView> domArrayBuffView = adoptRef(new DOMArrayB
ufferView(view.get())); |
550 // TODO(terry): Had to move protected constructor to public in | 594 // TODO(terry): Had to move protected constructor to public in |
551 // core/dom/DOMArrayBufferView.h | 595 // core/dom/DOMArrayBufferView.h |
552 RefPtr<DOMArrayBufferView> domArrayBuffView = new DOMArrayBufferView
(view.get()); | |
553 return blink::toV8(DOMDataView::create(domArrayBuffView->bufferBase(
), | 596 return blink::toV8(DOMDataView::create(domArrayBuffView->bufferBase(
), |
554 domArrayBuffView->byteOffset(), | 597 domArrayBuffView->byteOffset(), |
555 domArrayBuffView->byteLength()), | 598 domArrayBuffView->byteLength()), |
556 state->context()->Global(), | 599 state->context()->Global(), |
557 state->isolate()); | 600 state->isolate()); |
558 } | 601 } |
559 default: | 602 default: |
560 ASSERT_NOT_REACHED(); | 603 ASSERT_NOT_REACHED(); |
561 return v8::Handle<v8::Value>(); | 604 return v8::Handle<v8::Value>(); |
562 } | 605 } |
563 } | 606 } |
564 | 607 |
565 Dart_Handle V8Converter::arrayBufferViewToDart(v8::Handle<v8::Object> object, Da
rt_Handle& exception) | 608 Dart_Handle V8Converter::arrayBufferViewToDart(v8::Handle<v8::Object> object, Da
rt_Handle& exception) |
566 { | 609 { |
567 RefPtr<ArrayBufferView> view = V8ArrayBufferView::toImpl(object)->view(); | 610 RefPtr<ArrayBufferView> view = V8ArrayBufferView::toImpl(object)->view(); |
568 return DartUtilities::arrayBufferViewToDart(view.get()); | 611 return DartUtilities::arrayBufferViewToDart(view.get()); |
569 } | 612 } |
570 | 613 |
571 } // namespace blink | 614 } // namespace blink |
OLD | NEW |