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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/execution.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 var result = Constructor ? new (Instantiate(Constructor))() : {}; 52 var result = Constructor ? new (Instantiate(Constructor))() : {};
53 ConfigureTemplateInstance(result, data); 53 ConfigureTemplateInstance(result, data);
54 return result; 54 return result;
55 default: 55 default:
56 throw 'Unknown API tag <' + tag + '>'; 56 throw 'Unknown API tag <' + tag + '>';
57 } 57 }
58 } 58 }
59 59
60 60
61 function InstantiateFunction(data, name) { 61 function InstantiateFunction(data, name) {
62 // We need a reference to kApiFunctionCache in the stack frame
63 // if we need to bail out from a stack overflow.
64 var cache = kApiFunctionCache;
62 var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset); 65 var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset);
63 if (!(serialNumber in kApiFunctionCache)) { 66 var isFunctionCached =
64 kApiFunctionCache[serialNumber] = null; 67 (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
65 var fun = %CreateApiFunction(data); 68 (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
66 if (name) %FunctionSetName(fun, name); 69 if (!isFunctionCached) {
67 kApiFunctionCache[serialNumber] = fun; 70 try {
68 var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset); 71 kApiFunctionCache[serialNumber] = null;
69 fun.prototype = prototype ? Instantiate(prototype) : {}; 72 var fun = %CreateApiFunction(data);
70 %SetProperty(fun.prototype, "constructor", fun, DONT_ENUM); 73 if (name) %FunctionSetName(fun, name);
71 var parent = %GetTemplateField(data, kApiParentTemplateOffset); 74 kApiFunctionCache[serialNumber] = fun;
72 if (parent) { 75 var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset);
73 var parent_fun = Instantiate(parent); 76 fun.prototype = prototype ? Instantiate(prototype) : {};
74 fun.prototype.__proto__ = parent_fun.prototype; 77 %SetProperty(fun.prototype, "constructor", fun, DONT_ENUM);
78 var parent = %GetTemplateField(data, kApiParentTemplateOffset);
79 if (parent) {
80 var parent_fun = Instantiate(parent);
81 fun.prototype.__proto__ = parent_fun.prototype;
82 }
83 ConfigureTemplateInstance(fun, data);
84 } catch (e) {
85 cache[serialNumber] = -1;
86 throw e;
75 } 87 }
76 ConfigureTemplateInstance(fun, data);
77 } 88 }
78 return kApiFunctionCache[serialNumber]; 89 return kApiFunctionCache[serialNumber];
79 } 90 }
80 91
81 92
82 function ConfigureTemplateInstance(obj, data) { 93 function ConfigureTemplateInstance(obj, data) {
83 var properties = %GetTemplateField(data, kApiPropertyListOffset); 94 var properties = %GetTemplateField(data, kApiPropertyListOffset);
84 if (properties) { 95 if (properties) {
85 // Disable access checks while instantiating the object. 96 // Disable access checks while instantiating the object.
86 var requires_access_checks = %DisableAccessChecks(obj); 97 var requires_access_checks = %DisableAccessChecks(obj);
87 try { 98 try {
88 for (var i = 0; i < properties[0]; i += 3) { 99 for (var i = 0; i < properties[0]; i += 3) {
89 var name = properties[i + 1]; 100 var name = properties[i + 1];
90 var prop_data = properties[i + 2]; 101 var prop_data = properties[i + 2];
91 var attributes = properties[i + 3]; 102 var attributes = properties[i + 3];
92 var value = Instantiate(prop_data, name); 103 var value = Instantiate(prop_data, name);
93 %SetProperty(obj, name, value, attributes); 104 %SetProperty(obj, name, value, attributes);
94 } 105 }
95 } finally { 106 } finally {
96 if (requires_access_checks) %EnableAccessChecks(obj); 107 if (requires_access_checks) %EnableAccessChecks(obj);
97 } 108 }
98 } 109 }
99 } 110 }
OLDNEW
« 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