I'm newbie at javascript engine. In optimization phases, if implicit call
is in some block, optimizer need to add some check for this block. In this context, what implicit call
exactly means?
As i understand, i think below one is implicit call(cb function)
.
Is that right?
function foo(x, cb){
let arr = [1,2,3,4];
cb();
return arr[1];
}
V8 developer here. I'm afraid I'm not sure what you mean, so I'll give it my best guess: an "implicit call" is a call that's not immediately obvious from its syntax.
The call in your example is very explicit: anyone (human or compiler) looking at the code can immediately see that there's a call there. But consider this example:
function addFields(a, b) {
return a.field + b.field;
}
No calls, right? But now consider code like this elsewhere in the application:
var b = {field: 42};
var a = {get field() {delete b.field; return 0;}}
console.log(addFields(a, b));
Suddenly, what looks like a simple field load will implicitly call a user-defined function, which could have all sorts of side effects (like modifying an unrelated object).
Other examples of implicit calls are expressions like "the value is: " + x
, which will implicitly call x.toString()
if x
is not a String already.