map-override

map-override

The map-override snippet overrides functions under Map.prototype to change their behaviour.

Parameters

Name

Description

Mandatory

Default

method

The Map function to override: set, get, has.

Yes

n.a.

needle

String or regex used to determine which calls to trap. For set this matches the value. For get and has this matches the key.

Yes

n.a.

returnValue

The return value for matched calls. For get — value to return. For has — true or false.

No

''

path

Path to look for the needle. Only relevant for set when checking object values.

No

''

stack

Comma separated list of strings to check in stack trace.

No

''

Filter examples

Filter

Result

map-override set test

Ignores map.set("key", "test").

map-override set /first.*second/

Ignores calls where value matches the regex.

map-override get key1 customValue

map.get("key1") always returns "customValue".

map-override has key1 false

map.has("key1") always returns false.

map-override set test '' '' ads.js

Ignores map.set with value "test" only for ads.js.

Debugging

Message

When

Definition

Wrapped Map.prototype.set/get/has

After wrapping

Calls are intercepted.

Map.set is ignored for value matching needle

Needle matches set call

The set call was ignored.

Map.get returned >>returnValue>> for key

Needle matches get call

get returned the overridden value.

Map.has returned >>returnValue>> for key

Needle matches has call

has returned the overridden value.