Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Unified Diff: src/apinatives.js

Issue 17354: Do not cache functions until we know they are fully constructed. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/execution.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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];
}
« no previous file with comments | « no previous file | src/execution.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698