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

Unified Diff: src/apinatives.js

Issue 253603003: Pass in the prototype to CreateApiFunction rather than setting it on the result. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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/bootstrapper.cc » ('j') | src/factory.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/apinatives.js
diff --git a/src/apinatives.js b/src/apinatives.js
index 6431901bf239d87b1e4235337204ac963df79d85..71c78aec5fa49782e72587eee45802f5eb91a755 100644
--- a/src/apinatives.js
+++ b/src/apinatives.js
@@ -71,31 +71,29 @@ function InstantiateFunction(data, name) {
(serialNumber in cache) && (cache[serialNumber] != kUninitialized);
if (!isFunctionCached) {
try {
- var fun = %CreateApiFunction(data);
- if (name) %FunctionSetName(fun, name);
var flags = %GetTemplateField(data, kApiFlagOffset);
- var doNotCache = flags & (1 << kDoNotCacheBit);
- if (!doNotCache) cache[serialNumber] = fun;
- if (flags & (1 << kRemovePrototypeBit)) {
- %FunctionRemovePrototype(fun);
- } else {
- var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset);
- // Note: Do not directly use an object template as a condition, our
- // internal ToBoolean doesn't handle that!
- fun.prototype = typeof prototype === 'undefined' ?
- {} : Instantiate(prototype);
- if (flags & (1 << kReadOnlyPrototypeBit)) {
- %FunctionSetReadOnlyPrototype(fun);
- }
- %SetProperty(fun.prototype, "constructor", fun, DONT_ENUM);
+ var has_proto = !(flags & (1 << kRemovePrototypeBit));
+ var prototype;
+ if (has_proto) {
+ var template = %GetTemplateField(data, kApiPrototypeTemplateOffset);
+ prototype = typeof template === 'undefined'
+ ? {} : Instantiate(template);
+
var parent = %GetTemplateField(data, kApiParentTemplateOffset);
// Note: Do not directly use a function template as a condition, our
// internal ToBoolean doesn't handle that!
- if (!(typeof parent === 'undefined')) {
+ if (typeof parent !== 'undefined') {
var parent_fun = Instantiate(parent);
- %SetPrototype(fun.prototype, parent_fun.prototype);
+ %SetPrototype(prototype, parent_fun.prototype);
}
}
+ var fun = %CreateApiFunction(data, prototype);
+ if (name) %FunctionSetName(fun, name);
+ var doNotCache = flags & (1 << kDoNotCacheBit);
+ if (!doNotCache) cache[serialNumber] = fun;
+ if (has_proto && flags & (1 << kReadOnlyPrototypeBit)) {
+ %FunctionSetReadOnlyPrototype(fun);
+ }
ConfigureTemplateInstance(fun, data);
if (doNotCache) return fun;
} catch (e) {
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | src/factory.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698