Chromium Code Reviews| Index: src/apinatives.js |
| =================================================================== |
| --- src/apinatives.js (revision 1050) |
| +++ src/apinatives.js (working copy) |
| @@ -59,21 +59,32 @@ |
| 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); |
| - if (!(serialNumber in kApiFunctionCache)) { |
| - kApiFunctionCache[serialNumber] = null; |
| - var fun = %CreateApiFunction(data); |
| - if (name) %FunctionSetName(fun, name); |
| - kApiFunctionCache[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; |
| + var isFunctionCached = |
| + (serialNumber in kApiFunctionCache) && |
|
Mads Ager (chromium)
2009/01/13 07:00:39
Use the local variable 'cache' throughout this fun
olehougaard
2009/01/13 07:13:05
Fixed
|
| + (kApiFunctionCache[serialNumber] != -1); |
|
Mads Ager (chromium)
2009/01/13 07:00:39
How about introducing a named constants in macros.
olehougaard
2009/01/13 07:13:05
I would, but I wouldn't be able to look it up in t
olehougaard
2009/01/13 07:15:41
Uh, this is rubbish. I guess I can introduce a con
|
| + if (!isFunctionCached) { |
| + try { |
| + kApiFunctionCache[serialNumber] = null; |
| + var fun = %CreateApiFunction(data); |
| + if (name) %FunctionSetName(fun, name); |
| + kApiFunctionCache[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] = -1; |
| + throw e; |
| } |
| - ConfigureTemplateInstance(fun, data); |
| } |
| return kApiFunctionCache[serialNumber]; |
| } |