summaryrefslogtreecommitdiff
path: root/chromium/v8/src/objects/arguments.tq
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/v8/src/objects/arguments.tq')
-rw-r--r--chromium/v8/src/objects/arguments.tq109
1 files changed, 78 insertions, 31 deletions
diff --git a/chromium/v8/src/objects/arguments.tq b/chromium/v8/src/objects/arguments.tq
index 5211707eae9..e1637056f7f 100644
--- a/chromium/v8/src/objects/arguments.tq
+++ b/chromium/v8/src/objects/arguments.tq
@@ -26,7 +26,69 @@ extern shape JSStrictArgumentsObject extends JSArgumentsObject {
length: JSAny;
}
-type SloppyArgumentsElements extends FixedArray;
+// Helper class to access FAST_ and SLOW_SLOPPY_ARGUMENTS_ELEMENTS, dividing
+// arguments into two types for a given SloppyArgumentsElements object:
+// mapped and unmapped.
+//
+// For clarity SloppyArgumentsElements fields are qualified with "elements."
+// below.
+//
+// Mapped arguments are actual arguments. Unmapped arguments are values added
+// to the arguments object after it was created for the call. Mapped arguments
+// are stored in the context at indexes given by elements.mapped_entries[key].
+// Unmapped arguments are stored as regular indexed properties in the arguments
+// array which can be accessed from elements.arguments.
+//
+// elements.length is min(number_of_actual_arguments,
+// number_of_formal_arguments) for a concrete call to a function.
+//
+// Once a SloppyArgumentsElements is generated, lookup of an argument with index
+// |key| in |elements| works as follows:
+//
+// If key >= elements.length then attempt to look in the unmapped arguments
+// array and return the value at key, missing to the runtime if the unmapped
+// arguments array is not a fixed array or if key >= elements.arguments.length.
+//
+// Otherwise, t = elements.mapped_entries[key]. If t is the hole, then the
+// entry has been deleted fron the arguments object, and value is looked up in
+// the unmapped arguments array, as described above. Otherwise, t is a Smi
+// index into the context array specified at elements.context, and the return
+// value is elements.context[t].
+//
+// A graphic representation of a SloppyArgumentsElements object and a
+// corresponding unmapped arguments FixedArray:
+//
+// SloppyArgumentsElements
+// +---+-----------------------+
+// | Context context |
+// +---------------------------+
+// | FixedArray arguments +----+ HOLEY_ELEMENTS
+// +---------------------------+ v-----+-----------+
+// | 0 | Object mapped_entries | | 0 | the_hole |
+// |...| ... | | ... | ... |
+// |n-1| Object mapped_entries | | n-1 | the_hole |
+// +---------------------------+ | n | element_1 |
+// | ... | ... |
+// |n+m-1| element_m |
+// +-----------------+
+//
+// The elements.arguments backing store kind depends on the ElementsKind of
+// the outer JSArgumentsObject:
+// - FAST_SLOPPY_ARGUMENTS_ELEMENTS: HOLEY_ELEMENTS
+// - SLOW_SLOPPY_ARGUMENTS_ELEMENTS: DICTIONARY_ELEMENTS
+@export
+class SloppyArgumentsElements extends FixedArrayBase {
+ context: Context;
+ arguments: FixedArray;
+ mapped_entries[length]: Smi|TheHole;
+}
+
+macro NewSloppyArgumentsElements<Iterator: type>(
+ length: Smi, context: Context, arguments: FixedArray,
+ it: Iterator): SloppyArgumentsElements {
+ return new
+ SloppyArgumentsElements{length, context, arguments, mapped_entries: ...it};
+}
@generateCppClass
@generatePrint
@@ -49,7 +111,7 @@ macro NewJSStrictArgumentsObject(implicit context: Context)(
}
macro NewJSSloppyArgumentsObject(implicit context: Context)(
- elements: FixedArray, callee: JSFunction): JSSloppyArgumentsObject {
+ elements: FixedArrayBase, callee: JSFunction): JSSloppyArgumentsObject {
const map = GetSloppyArgumentsMap();
return new JSSloppyArgumentsObject{
map,
@@ -61,7 +123,7 @@ macro NewJSSloppyArgumentsObject(implicit context: Context)(
}
macro NewJSFastAliasedArgumentsObject(implicit context: Context)(
- elements: FixedArray, length: Smi,
+ elements: FixedArrayBase, length: Smi,
callee: JSFunction): JSSloppyArgumentsObject {
// TODO(danno): FastAliasedArguments should really be a type for itself
const map = GetFastAliasedArgumentsMap();
@@ -75,28 +137,17 @@ macro NewJSFastAliasedArgumentsObject(implicit context: Context)(
}
struct ParameterMapIterator {
- macro Next(): Object labels NoMore {
- const currentMapSlotCopy = this.currentMapSlot++;
- if (currentMapSlotCopy > 1) {
- if (this.currentIndex == this.endInterationIndex) goto NoMore;
- this.currentIndex--;
- return Convert<Smi>(this.currentIndex);
- } else if (currentMapSlotCopy == 0) {
- return this.context;
- } else {
- assert(currentMapSlotCopy == 1);
- return this.elements;
- }
+ macro Next(): Smi labels NoMore {
+ if (this.currentIndex == this.endInterationIndex) goto NoMore;
+ this.currentIndex--;
+ return Convert<Smi>(this.currentIndex);
}
- const context: Context;
- const elements: FixedArray;
currentIndex: intptr;
const endInterationIndex: intptr;
- currentMapSlot: intptr;
}
macro NewParameterMapIterator(
- context: Context, elements: FixedArray, formalParameterCount: intptr,
+ context: Context, formalParameterCount: intptr,
mappedCount: intptr): ParameterMapIterator {
const flags = context.scope_info.flags;
let contextHeaderSize: intptr = MIN_CONTEXT_SLOTS;
@@ -112,11 +163,8 @@ macro NewParameterMapIterator(
const afterLastContextIndex = contextHeaderSize + formalParameterCount;
const firstContextIndex = afterLastContextIndex - mappedCount;
return ParameterMapIterator{
- context,
- elements,
currentIndex: afterLastContextIndex,
- endInterationIndex: firstContextIndex,
- currentMapSlot: 0
+ endInterationIndex: firstContextIndex
};
}
@@ -188,17 +236,16 @@ macro NewSloppyArguments(implicit context: Context)(
const mappedCount = IntPtrMin(formalParameterCount, argumentCount);
const it = NewParameterValueIterator(mappedCount, arguments);
const parameterValues = NewFixedArray(argumentCount, it);
- let paramIter = NewParameterMapIterator(
- context, parameterValues, formalParameterCount, mappedCount);
- const elementsLength =
- Convert<Smi>(mappedCount + kSloppyArgumentsParameterMapStart);
- const map = kSloppyArgumentsElementsMap;
- const elements = new
- FixedArray{map, length: elementsLength, objects: ...paramIter};
+ let paramIter =
+ NewParameterMapIterator(context, formalParameterCount, mappedCount);
+ const elementsLength = Convert<Smi>(mappedCount);
+ const elements = NewSloppyArgumentsElements(
+ elementsLength, context, parameterValues, paramIter);
const length = Convert<Smi>(argumentCount);
return NewJSFastAliasedArgumentsObject(elements, length, callee);
}
-}
+
+} // namespace arguments
@export
macro EmitFastNewAllArguments(implicit context: Context)(