Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 | var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
|
---|
| 3 | var toLength = require('../internals/to-length');
|
---|
| 4 | var toOffset = require('../internals/to-offset');
|
---|
| 5 | var toObject = require('../internals/to-object');
|
---|
| 6 | var fails = require('../internals/fails');
|
---|
| 7 |
|
---|
| 8 | var aTypedArray = ArrayBufferViewCore.aTypedArray;
|
---|
| 9 | var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod;
|
---|
| 10 |
|
---|
| 11 | var FORCED = fails(function () {
|
---|
| 12 | // eslint-disable-next-line es/no-typed-arrays -- required for testing
|
---|
| 13 | new Int8Array(1).set({});
|
---|
| 14 | });
|
---|
| 15 |
|
---|
| 16 | // `%TypedArray%.prototype.set` method
|
---|
| 17 | // https://tc39.es/ecma262/#sec-%typedarray%.prototype.set
|
---|
| 18 | exportTypedArrayMethod('set', function set(arrayLike /* , offset */) {
|
---|
| 19 | aTypedArray(this);
|
---|
| 20 | var offset = toOffset(arguments.length > 1 ? arguments[1] : undefined, 1);
|
---|
| 21 | var length = this.length;
|
---|
| 22 | var src = toObject(arrayLike);
|
---|
| 23 | var len = toLength(src.length);
|
---|
| 24 | var index = 0;
|
---|
| 25 | if (len + offset > length) throw RangeError('Wrong length');
|
---|
| 26 | while (index < len) this[offset + index] = src[index++];
|
---|
| 27 | }, FORCED);
|
---|
Note:
See
TracBrowser
for help on using the repository browser.