| Index: src/arraybuffer.js
|
| diff --git a/src/generator.js b/src/arraybuffer.js
|
| similarity index 51%
|
| copy from src/generator.js
|
| copy to src/arraybuffer.js
|
| index 5e61091565567bf9d516a45d0efd72add6aa33af..2b0c3dd85b1107bc2f5a98d355a24ad7a974e9fe 100644
|
| --- a/src/generator.js
|
| +++ b/src/arraybuffer.js
|
| @@ -27,58 +27,74 @@
|
|
|
| "use strict";
|
|
|
| -// This file relies on the fact that the following declarations have been made
|
| -// in runtime.js:
|
| -// var $Function = global.Function;
|
| +var $ArrayBuffer = global.ArrayBuffer;
|
|
|
| -// ----------------------------------------------------------------------------
|
| +// -------------------------------------------------------------------
|
|
|
| -
|
| -// TODO(wingo): Give link to specification. For now, the following diagram is
|
| -// the spec:
|
| -// http://wiki.ecmascript.org/lib/exe/fetch.php?cache=cache&media=harmony:es6_generator_object_model_3-29-13.png
|
| -
|
| -function GeneratorObjectNext() {
|
| - if (!IS_GENERATOR(this)) {
|
| - throw MakeTypeError('incompatible_method_receiver',
|
| - ['[Generator].prototype.next', this]);
|
| +function ArrayBufferConstructor(byteLength) { // length = 1
|
| + if (%_IsConstructCall()) {
|
| + var l = TO_POSITIVE_INTEGER(byteLength);
|
| + %ArrayBufferInitialize(this, l);
|
| + } else {
|
| + return new $ArrayBuffer(byteLength);
|
| }
|
| -
|
| - return %_GeneratorSend(this, void 0);
|
| }
|
|
|
| -function GeneratorObjectSend(value) {
|
| - if (!IS_GENERATOR(this)) {
|
| +function ArrayBufferGetByteLength() {
|
| + if (!IS_ARRAYBUFFER(this)) {
|
| throw MakeTypeError('incompatible_method_receiver',
|
| - ['[Generator].prototype.send', this]);
|
| + ['ArrayBuffer.prototype.byteLength', this]);
|
| }
|
| -
|
| - return %_GeneratorSend(this, value);
|
| + return %ArrayBufferGetByteLength(this);
|
| }
|
|
|
| -function GeneratorObjectThrow(exn) {
|
| - if (!IS_GENERATOR(this)) {
|
| +// ES6 Draft 15.13.5.5.3
|
| +function ArrayBufferSlice(start, end) {
|
| + if (!IS_ARRAYBUFFER(this)) {
|
| throw MakeTypeError('incompatible_method_receiver',
|
| - ['[Generator].prototype.throw', this]);
|
| + ['ArrayBuffer.prototype.slice', this]);
|
| + }
|
| +
|
| + var relativeStart = TO_INTEGER(start);
|
| + var first;
|
| + if (relativeStart < 0) {
|
| + first = MathMax(this.byteLength + relativeStart, 0);
|
| + } else {
|
| + first = MathMin(relativeStart, this.byteLength);
|
| + }
|
| + var relativeEnd = IS_UNDEFINED(end) ? this.byteLength : TO_INTEGER(end);
|
| + var fin;
|
| + if (relativeEnd < 0) {
|
| + fin = MathMax(this.byteLength + relativeEnd, 0);
|
| + } else {
|
| + fin = MathMin(relativeEnd, this.byteLength);
|
| }
|
|
|
| - return %_GeneratorThrow(this, exn);
|
| + var newLen = fin - first;
|
| + // TODO(dslomov): implement inheritance
|
| + var result = new $ArrayBuffer(newLen);
|
| +
|
| + %ArrayBufferSliceImpl(this, result, first);
|
| + return result;
|
| }
|
|
|
| -function SetUpGenerators() {
|
| +function SetUpArrayBuffer() {
|
| %CheckIsBootstrapping();
|
| - var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
|
| - InstallFunctions(GeneratorObjectPrototype,
|
| - DONT_ENUM | DONT_DELETE | READ_ONLY,
|
| - ["next", GeneratorObjectNext,
|
| - "send", GeneratorObjectSend,
|
| - "throw", GeneratorObjectThrow]);
|
| - %SetProperty(GeneratorObjectPrototype, "constructor",
|
| - GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY);
|
| - %SetPrototype(GeneratorFunctionPrototype, $Function.prototype);
|
| - %SetProperty(GeneratorFunctionPrototype, "constructor",
|
| - GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY);
|
| - %SetPrototype(GeneratorFunction, $Function);
|
| +
|
| + // Set up the ArrayBuffer constructor function.
|
| + %SetCode($ArrayBuffer, ArrayBufferConstructor);
|
| + %FunctionSetPrototype($ArrayBuffer, new $Object());
|
| +
|
| + // Set up the constructor property on the ArrayBuffer prototype object.
|
| + %SetProperty($ArrayBuffer.prototype, "constructor", $ArrayBuffer, DONT_ENUM);
|
| +
|
| + InstallGetter($ArrayBuffer.prototype, "byteLength", ArrayBufferGetByteLength);
|
| +
|
| + InstallFunctions($ArrayBuffer.prototype, DONT_ENUM, $Array(
|
| + "slice", ArrayBufferSlice
|
| + ));
|
| }
|
|
|
| -SetUpGenerators();
|
| +SetUpArrayBuffer();
|
| +
|
| +
|
|
|