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

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

Issue 1470193002: Array/TypedArray/ArrayBuffer method subclassing and @@species (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase 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 | « src/builtins.cc ('k') | src/js/regexp.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);
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 if (%_ArrayBufferGetByteLength(result) < newLen) {
74 throw MakeTypeError(kArrayBufferTooShort);
75 }
76 if (result === this) {
77 throw MakeTypeError(kArrayBufferSpeciesThis);
78 }
67 79
68 %ArrayBufferSliceImpl(this, result, first); 80 %ArrayBufferSliceImpl(this, result, first, newLen);
69 return result; 81 return result;
70 } 82 }
71 83
72 utils.InstallGetter(GlobalArrayBuffer.prototype, "byteLength", 84 utils.InstallGetter(GlobalArrayBuffer.prototype, "byteLength",
73 ArrayBufferGetByteLen); 85 ArrayBufferGetByteLen);
74 86
75 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ 87 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [
76 "slice", ArrayBufferSlice 88 "slice", ArrayBufferSlice
77 ]); 89 ]);
78 90
79 }) 91 })
OLDNEW
« no previous file with comments | « src/builtins.cc ('k') | src/js/regexp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698