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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/js/runtime.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/arraybuffer.js
diff --git a/src/js/arraybuffer.js b/src/js/arraybuffer.js
index 1ee68ca291b0ccc6c6affc79af5c7bcc6b90c493..f0273c71ed757515a096fa554399bca171857d4c 100644
--- a/src/js/arraybuffer.js
+++ b/src/js/arraybuffer.js
@@ -15,11 +15,13 @@ var GlobalArrayBuffer = global.ArrayBuffer;
var MakeTypeError;
var MaxSimple;
var MinSimple;
+var SpeciesConstructor;
utils.Import(function(from) {
MakeTypeError = from.MakeTypeError;
MaxSimple = from.MaxSimple;
MinSimple = from.MinSimple;
+ SpeciesConstructor = from.SpeciesConstructor;
});
// -------------------------------------------------------------------
@@ -62,10 +64,21 @@ function ArrayBufferSlice(start, end) {
fin = first;
}
var newLen = fin - first;
- // TODO(dslomov): implement inheritance
- var result = new GlobalArrayBuffer(newLen);
+ var constructor = SpeciesConstructor(this, GlobalArrayBuffer, true);
+ var result = new constructor(newLen);
+ if (!IS_ARRAYBUFFER(result)) {
+ throw MakeTypeError(kIncompatibleMethodReceiver,
+ 'ArrayBuffer.prototype.slice', result);
+ }
+ // TODO(littledan): Check for a detached ArrayBuffer
+ if (result === this) {
+ throw MakeTypeError(kArrayBufferSpeciesThis);
+ }
+ if (%_ArrayBufferGetByteLength(result) < newLen) {
+ throw MakeTypeError(kArrayBufferTooShort);
+ }
- %ArrayBufferSliceImpl(this, result, first);
+ %ArrayBufferSliceImpl(this, result, first, newLen);
return result;
}
« 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