当前位置:网站首页>JS precompiled
JS precompiled
2022-07-16 06:05:00 【M78_ Domestic 007】
JS There are three steps to complete the explanation and execution :1. Syntax analysis ;2. precompile ( Global precompiling 、 Function precompile );3. Execute statement .
make a concrete analysis :
1、 Syntax analysis
Analyze whether the code is correct Lexical analysis
2、 Implicit operation ==> precompile : After the function call Before running the code
2.1 Each call of the function will generate an object Activation Object, abbreviation AO object : Execution time context object
2.2. to AO Object to add members : Names of local variables and formal parameter variables inside the function As AO The property name of the object When the formal parameter is the same as the local variable No effect
2.3. Assign the passed argument to AO Object properties
2.4. Local function declaration , assignment Let the name of the local function be AO Object has the same member name , Assign the function body to this attribute
3. Run code : The pre compiled ones are not running
Case study :
<script>
function fm(a) {
console.log(a) //100
var a=10 // to a The assignment is 10
function fn () {}
console.log(a)
}
var b=100
fm(b)
/*
analysis :
1、 Check the code for errors
Call function fm(b)
2、 precompile
So let's create one AO object {}
Then the names of local variables and formal parameter variables inside the function As AO The property name of the object AO:{a:undefined}
Assign the passed argument to AO Object properties AO:{a:100}
Let the name of the local function be AO Object has the same member name , Assign the function body to this attribute
AO:{a:100,fn:function fn () {}}
3、 Run code The pre compiled ones are not running
here fm In function code :
function fm(a) {
AO:{a:100,fn:function fn () {}}
console.log(a) //100
a=10 // to a The assignment is 10
}
*/
</script>When the global scope runs code There is also precompiled ==> Global precompiling
Unlike function precompiling , What is generated is the object Global Object (GO).
step :
1. Generate an object Global Object (GO)
2. Put all global variables Set to GO The property name
3. Put all function names As GO Member name of , Assign the function body to this member
4. Execute code
Case description :
<script>
console.log(a) //undefined
var a = 20
function fn() {
console.log(66)
}
/*
1、 Check the code for errors
2、 Global precompiling :
2.1、 Generate an object Global Object (GO)
GO:{}
2.2、 Put all global variables Set to GO The property name
GO:{a:undefend}
2.3、 Put all function names As GO Member name of , Assign the function body to this member
GO:{a:undefend,fn:function fn(){console.log(66)}}
3. Execute code
GO:{a:undefend==>20,fn:function fn(){console.log(66)}}
console.log(a) //undefined
a = 20
*/
</script>
There is another step in global precompiling ==> Run in different environments js The code is different
GO All members of the object are shallow copied to the environment object window
node.js There is no such step in the environment
Expand knowledge : About visiting members console.log(a) What I visited was GO Members of the object ( If there is no scope in the chain, an error will be reported )
console.log(window.a) Don't complain Prototype chain did not return undefined
边栏推荐
- PHP docking Alipay web payment -tp5.1 framework
- [wustctf2020] plain
- 摩斯隐私计算一体机全项通过深圳国金测评中心83项测评
- FTP upload file script description
- BUUCTF 面具下的flag
- 欧拉Talk | 开发者社区体验坦白局7月14日19:30约起
- Simply understand the three handshakes and four waves of TCP
- Notes on network communication security -- static routing and experiment
- 36.js-- prototype chain 2-- (mainly written test questions)
- 内网渗透笔记——:)一个笑脸
猜你喜欢

36.js-- prototype chain 2-- (mainly written test questions)

开源实习 | Compiler SIG 实习任务正式发布,欢迎报名申请!

Notes 2 of network communication security
![[NCTF2019]Fake XML cookbook](/img/d4/e5ff896108c86179526a06911abd38.png)
[NCTF2019]Fake XML cookbook

SNMP started

网络安全应急响应-恶意代码分析技术
![[wustctf2020] plain](/img/48/d8e78424d582b60f238a2625854134.png)
[wustctf2020] plain

Simply understand the three handshakes and four waves of TCP

DVA data flow

El button display and disable
随机推荐
BUUCTF 九连环
41.js -- closure
编译原理-词法分析器设计
暑期沉淀web学习——php基础
38.js-- prototype exercise cases (face-to-face examination questions for proofreading)
MySQL-多表查询-内连接/外连接/自连接
内网渗透笔记——注册表自启动与msi提权
Nftscan Developer Platform launches Multi Chain NFT data pro API service
BUUCTF webshell后门
Convert list data to tree data
DVA data flow
MySQL master-slave server configuration experiment centos7
手摸手教学-利用原生POI对excel的导入导出以及阿里的easyexcel的基本操作
PHP docking Alipay web payment -tp5.1 framework
MySQL-多表查询-联合查询/子查询
网络通信安全部分笔记——OSPF理论及实验
[wustctf2020] plain
摩斯隐私计算一体机全项通过深圳国金测评中心83项测评
MySQL function string function / numeric function / date function / process control function
ES6 -- arrow function