Array Method `this` and Argument Boxing Check

1.0.0 · active · verified Sun Apr 19

This package, `es-array-method-boxes-properly`, is a niche utility designed to verify the spec compliance of `Array.prototype` methods in a given JavaScript environment. Specifically, it checks if a method like `map` or `forEach` properly "boxes" the `this` context (receiver) and the third argument (the array itself) when invoking the callback function. This is critical for ensuring consistent behavior across different JavaScript engines, especially regarding strict mode implications and how primitives are handled when passed as `this`. Currently at version 1.0.0, the package provides a stable API and is likely maintained on an as-needed basis, reflecting its role in foundational spec compliance rather than active feature development. It is primarily used by library authors or engine developers to detect subtle deviations from the ECMAScript specification in host environments.

Warnings

Install

Imports

Quickstart

Demonstrates how to import the `boxesProperly` function and use it to check the compliance of `Array.prototype.map` and `forEach` in the current runtime environment.

const boxesProperly = require('es-array-method-boxes-properly');

// Check if Array.prototype.map boxes 'this' and the third argument properly
const mapBoxesProperly = boxesProperly('map');
console.log(`Array.prototype.map boxes properly: ${mapBoxesProperly}`);

// Example for a method that is known to box differently in some older environments or custom implementations
const forEachBoxesProperly = boxesProperly('forEach');
console.log(`Array.prototype.forEach boxes properly: ${forEachBoxesProperly}`);

// You can use this to adapt behavior or report compliance issues
if (!mapBoxesProperly) {
  console.warn('Warning: Array.prototype.map implementation might not be spec-compliant regarding boxing.');
}

view raw JSON →