blob: 7e044e086b89b38b9247232fa1de0fb1ed5efd90 [file] [log] [blame]
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include 'src/builtins/builtins-array-gen.h'
namespace array {
// Naming convention from We have a similar intent but implement
// fastpaths using generics instead of using a class hierarchy for elements
// kinds specific implementations.
type GenericElementsAccessor;
type FastPackedSmiElements;
type FastPackedObjectElements;
type FastPackedDoubleElements;
type FastSmiOrObjectElements;
type FastDoubleElements;
type DictionaryElements;
macro EnsureWriteableFastElements(implicit context: Context)(array: JSArray) {
const elements: FixedArrayBase = array.elements;
if ( != kCOWMap) return;
// There are no COW *_DOUBLE_ELEMENTS arrays, so we are allowed to always
// extract FixedArrays and don't have to worry about FixedDoubleArrays.
const length: Smi = Cast<Smi>(array.length) otherwise unreachable;
array.elements =
ExtractFixedArray(elements, 0, length, length, kFixedArrays);
assert( != kCOWMap);
macro IsJSArray(implicit context: Context)(o: Object): bool {
typeswitch (o) {
case (JSArray): {
return true;
case (Object): {
return false;
macro LoadElementOrUndefined(a: FixedArray, i: Smi): Object {
const e: Object = a.objects[i];
return e == TheHole ? Undefined : e;
macro LoadElementOrUndefined(a: FixedDoubleArray, i: Smi): NumberOrUndefined {
try {
const f: float64 = LoadDoubleWithHoleCheck(a, i) otherwise IfHole;
return AllocateHeapNumberWithValue(f);
label IfHole {
return Undefined;
macro StoreArrayHole(elements: FixedDoubleArray, k: Smi): void {
StoreFixedDoubleArrayHoleSmi(elements, k);
macro StoreArrayHole(elements: FixedArray, k: Smi): void {
elements.objects[k] = TheHole;
extern macro SetPropertyLength(implicit context: Context)(Object, Number);