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

Side by Side Diff: src/arraybuffer.js

Issue 1345333002: src: Use simple/fast macro version of MinMax in JS (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Back from beginInt to startInt Created 5 years, 3 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/array.js ('k') | src/harmony-array.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 GlobalObject = global.Object; 15 var GlobalObject = global.Object;
16 var MathMax;
17 var MathMin;
18 var ToNumber; 16 var ToNumber;
19 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); 17 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
20 18
21 utils.Import(function(from) { 19 utils.Import(function(from) {
22 MathMax = from.MathMax;
23 MathMin = from.MathMin;
24 ToNumber = from.ToNumber; 20 ToNumber = from.ToNumber;
25 }); 21 });
26 22
27 // ------------------------------------------------------------------- 23 // -------------------------------------------------------------------
28 24
29 function ArrayBufferConstructor(length) { // length = 1 25 function ArrayBufferConstructor(length) { // length = 1
30 if (%_IsConstructCall()) { 26 if (%_IsConstructCall()) {
31 var byteLength = $toPositiveInteger(length, kInvalidArrayBufferLength); 27 var byteLength = $toPositiveInteger(length, kInvalidArrayBufferLength);
32 %ArrayBufferInitialize(this, byteLength, kNotShared); 28 %ArrayBufferInitialize(this, byteLength, kNotShared);
33 } else { 29 } else {
34 throw MakeTypeError(kConstructorNotFunction, "ArrayBuffer"); 30 throw MakeTypeError(kConstructorNotFunction, "ArrayBuffer");
35 } 31 }
36 } 32 }
37 33
38 function ArrayBufferGetByteLen() { 34 function ArrayBufferGetByteLen() {
39 if (!IS_ARRAYBUFFER(this)) { 35 if (!IS_ARRAYBUFFER(this)) {
40 throw MakeTypeError(kIncompatibleMethodReceiver, 36 throw MakeTypeError(kIncompatibleMethodReceiver,
41 'ArrayBuffer.prototype.byteLength', this); 37 'ArrayBuffer.prototype.byteLength', this);
42 } 38 }
43 return %_ArrayBufferGetByteLength(this); 39 return %_ArrayBufferGetByteLength(this);
44 } 40 }
45 41
46 // ES6 Draft 15.13.5.5.3 42 // ES6 Draft 15.13.5.5.3
47 function ArrayBufferSlice(start, end) { 43 function ArrayBufferSlice(start, end) {
48 if (!IS_ARRAYBUFFER(this)) { 44 if (!IS_ARRAYBUFFER(this)) {
49 throw MakeTypeError(kIncompatibleMethodReceiver, 45 throw MakeTypeError(kIncompatibleMethodReceiver,
50 'ArrayBuffer.prototype.slice', this); 46 'ArrayBuffer.prototype.slice', this);
51 } 47 }
52 48
53 var relativeStart = TO_INTEGER(start); 49 var startInt = TO_INTEGER(start);
54 if (!IS_UNDEFINED(end)) { 50 if (!IS_UNDEFINED(end)) {
55 end = TO_INTEGER(end); 51 var endInt = TO_INTEGER(end);
56 } 52 var byteLength = %_ArrayBufferGetByteLength(this);
57 var first;
58 var byte_length = %_ArrayBufferGetByteLength(this);
59 if (relativeStart < 0) {
60 first = MathMax(byte_length + relativeStart, 0);
61 } else { 53 } else {
62 first = MathMin(relativeStart, byte_length); 54 var byteLength = %_ArrayBufferGetByteLength(this);
Dan Ehrenberg 2015/09/16 21:34:21 Why did you move this inside of the conditional ra
skomski 2015/09/16 21:57:39 Same code as in SubArray; related to https://coder
Jakob Kummerow 2015/09/17 07:36:34 That's not a good reason. It didn't make sense the
skomski 2015/09/17 08:07:03 First one was not a reason rather I thought he mis
63 } 55 var endInt = byteLength;
64 var relativeEnd = IS_UNDEFINED(end) ? byte_length : end;
65 var fin;
66 if (relativeEnd < 0) {
67 fin = MathMax(byte_length + relativeEnd, 0);
68 } else {
69 fin = MathMin(relativeEnd, byte_length);
70 } 56 }
71 57
72 if (fin < first) { 58 if (startInt < 0) {
73 fin = first; 59 startInt = MAX_SIMPLE(byteLength + startInt, 0);
60 } else {
61 startInt = MIN_SIMPLE(startInt, byteLength);
74 } 62 }
75 var newLen = fin - first; 63
64 if (endInt < 0) {
65 endInt = MAX_SIMPLE(byteLength + endInt, 0);
66 } else {
67 endInt = MIN_SIMPLE(endInt, byteLength);
68 }
69
70 if (endInt < startInt) {
71 endInt = startInt;
72 }
73
74 var newLength = endInt - startInt;
76 // TODO(dslomov): implement inheritance 75 // TODO(dslomov): implement inheritance
77 var result = new GlobalArrayBuffer(newLen); 76 var result = new GlobalArrayBuffer(newLength);
78 77
79 %ArrayBufferSliceImpl(this, result, first); 78 %ArrayBufferSliceImpl(this, result, startInt);
80 return result; 79 return result;
81 } 80 }
82 81
83 function ArrayBufferIsViewJS(obj) { 82 function ArrayBufferIsViewJS(obj) {
84 return %ArrayBufferIsView(obj); 83 return %ArrayBufferIsView(obj);
85 } 84 }
86 85
87 86
88 // Set up the ArrayBuffer constructor function. 87 // Set up the ArrayBuffer constructor function.
89 %SetCode(GlobalArrayBuffer, ArrayBufferConstructor); 88 %SetCode(GlobalArrayBuffer, ArrayBufferConstructor);
(...skipping 11 matching lines...) Expand all
101 100
102 utils.InstallFunctions(GlobalArrayBuffer, DONT_ENUM, [ 101 utils.InstallFunctions(GlobalArrayBuffer, DONT_ENUM, [
103 "isView", ArrayBufferIsViewJS 102 "isView", ArrayBufferIsViewJS
104 ]); 103 ]);
105 104
106 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [ 105 utils.InstallFunctions(GlobalArrayBuffer.prototype, DONT_ENUM, [
107 "slice", ArrayBufferSlice 106 "slice", ArrayBufferSlice
108 ]); 107 ]);
109 108
110 }) 109 })
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/harmony-array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698