Created
October 6, 2010 17:14
-
-
Save tj/613704 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function InstantiateFunction(data, name) { | |
// We need a reference to kApiFunctionCache in the stack frame | |
// if we need to bail out from a stack overflow. | |
var cache = kApiFunctionCache; | |
var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset); | |
var isFunctionCached = | |
(serialNumber in cache) && (cache[serialNumber] != kUninitialized); | |
if (!isFunctionCached) { | |
try { | |
cache[serialNumber] = null; | |
var fun = %CreateApiFunction(data); | |
if (name) %FunctionSetName(fun, name); | |
cache[serialNumber] = fun; | |
var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset); | |
fun.prototype = prototype ? Instantiate(prototype) : {}; | |
%SetProperty(fun.prototype, "constructor", fun, DONT_ENUM); | |
var parent = %GetTemplateField(data, kApiParentTemplateOffset); | |
if (parent) { | |
var parent_fun = Instantiate(parent); | |
fun.prototype.__proto__ = parent_fun.prototype; | |
} | |
ConfigureTemplateInstance(fun, data); | |
} catch (e) { | |
cache[serialNumber] = kUninitialized; | |
throw e; | |
} | |
} | |
return cache[serialNumber]; | |
} |
v8's function init code, Tim was wondering where .constructor
came from
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is this?