-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This repository is part of a larger project!
The file "stack.js" contains a recursive function which could, if activated, shut down your browser. Please, use the project with caution and only if you know what you are doing.
Javascript offers the property caller which could be used to determine the function in which it was applied. Like the following example should show:
var list = [];
//"a" uses the property "caller"
function a()
{
//Iterates through all the functions in which function "a" exists
for(var f = a.caller; f; f = f.caller)
{
list.push(f);
}
}
//"b" calls "a"
function b()
{
a()
}
//"c" calls "b"
function c()
{
b();
}
//Calling sequence is c->b->a
c();
/*
======
Output
======
[ƒ, ƒ]
0: ƒ b()
1: ƒ c()
length: 2
*/
console.log(list);
This ability could be useful for implementing a Stack Trace, but that should be done with caution.
The reason for this, it seems, would be that the feature caller is not heavily supported anymore.
Also its usefulness in recursion should not be given(check function BuggyCall in file "stack.js").
The user interaction part could look like the content as seen below by starting "index.html" in a web browser and interacting with its features.
-
🅱️ utton "WORKS" activates a functional simple Stack Trace -
🅱️ utton "BUGGY" activates a recursive function, but efore that its call has to be activated within the file "stack.js" -
By pressing one of the described buttons, the "RESULT" area informs the user the needed steps to see the results.
To use the project just download the files and execute "index.html". Note that all files(folder "wiki_images" excluded) should be placed in the same folder so that the functionality of the code is guaranteed.
This knowledge was gained:
- Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman
Sources:
- What and where are the stack and heap? asked by mattshane and answered by Jeff Hill