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

Side by Side Diff: src/js/arraybuffer.js

Issue 1574903004: TypedArray and ArrayBuffer support for @@species (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Upload tests and make some code more clear Created 4 years, 11 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/js/runtime.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var GlobalArrayBuffer = global.ArrayBuffer; 14 var GlobalArrayBuffer = global.ArrayBuffer;
15 var MakeTypeError; 15 var MakeTypeError;
16 var MaxSimple; 16 var MaxSimple;
17 var MinSimple; 17 var MinSimple;
18 var SpeciesConstructor;
18 19
19 utils.Import(function(from) { 20 utils.Import(function(from) {
20 MakeTypeError = from.MakeTypeError; 21 MakeTypeError = from.MakeTypeError;
21 MaxSimple = from.MaxSimple; 22 MaxSimple = from.MaxSimple;
22 MinSimple = from.MinSimple; 23 MinSimple = from.MinSimple;
24 SpeciesConstructor = from.SpeciesConstructor;
23 }); 25 });
24 26
25 // ------------------------------------------------------------------- 27 // -------------------------------------------------------------------
26 28
27 function ArrayBufferGetByteLen() { 29 function ArrayBufferGetByteLen() {
28 if (!IS_ARRAYBUFFER(this)) { 30 if (!IS_ARRAYBUFFER(this)) {
29 throw MakeTypeError(kIncompatibleMethodReceiver, 31 throw MakeTypeError(kIncompatibleMethodReceiver,
30 'ArrayBuffer.prototype.byteLength', this); 32 'ArrayBuffer.prototype.byteLength', this);
31 } 33 }
32 return %_ArrayBufferGetByteLength(this); 34 return %_ArrayBufferGetByteLength(this);
(...skipping 22 matching lines...) Expand all
55 if (relativeEnd < 0) { 57 if (relativeEnd < 0) {
56 fin = MaxSimple(byte_length + relativeEnd, 0); 58 fin = MaxSimple(byte_length + relativeEnd, 0);
57 } else { 59 } else {
58 fin = MinSimple(relativeEnd, byte_length); 60 fin = MinSimple(relativeEnd, byte_length);
59 } 61 }
60 62
61 if (fin < first) { 63 if (fin < first) {
62 fin = first; 64 fin = first;
63 } 65 }
64 var newLen = fin - first; 66 var newLen = fin - first;
65 // TODO(dslomov): implement inheritance 67 var constructor = SpeciesConstructor(this, GlobalArrayBuffer, true);
66 var result = new GlobalArrayBuffer(newLen); 68 var result = new constructor(newLen);
69 if (!IS_ARRAYBUFFER(result)) {
70 throw MakeTypeError(kIncompatibleMethodReceiver,
71 'ArrayBuffer.prototype.slice', result);
72 }
73 // TODO(littledan): Check for a detached ArrayBuffer
74 if (result === this) {
75 throw MakeTypeError(kArrayBufferSpeciesThis);
76 }
77 if (%_ArrayBufferGetByteLength(result) < newLen) {
78 throw MakeTypeError(kArrayBufferTooShort);
79 }
67 80
68 %ArrayBufferSliceImpl(this, result, first); 81 %ArrayBufferSliceImpl(this, result, first, newLen);
69 return result; 82 return result;
70 } 83 }
71 84
72 utils.InstallGetter(GlobalArrayBuffer.prototype, "byteLength", 85 utils.InstallGetter(GlobalArrayBuffer.prototype, "byteLength",
73 ArrayBufferGetByteLen); 86 ArrayBufferGetByteLen);
74 87
75 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ 88 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [
76 "slice", ArrayBufferSlice 89 "slice", ArrayBufferSlice
77 ]); 90 ]);
78 91
79 }) 92 })
OLDNEW
« no previous file with comments | « no previous file | src/js/runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698