OLD | NEW |
---|---|
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 | 42 |
43 | 43 |
44 function Instantiate(data, name) { | 44 function Instantiate(data, name) { |
45 if (!%IsTemplate(data)) return data; | 45 if (!%IsTemplate(data)) return data; |
46 var tag = %GetTemplateField(data, kApiTagOffset); | 46 var tag = %GetTemplateField(data, kApiTagOffset); |
47 switch (tag) { | 47 switch (tag) { |
48 case kFunctionTag: | 48 case kFunctionTag: |
49 return InstantiateFunction(data, name); | 49 return InstantiateFunction(data, name); |
50 case kNewObjectTag: | 50 case kNewObjectTag: |
51 var Constructor = %GetTemplateField(data, kApiConstructorOffset); | 51 var Constructor = %GetTemplateField(data, kApiConstructorOffset); |
52 var result = Constructor ? new (Instantiate(Constructor))() : {}; | 52 // Note: Do not directly use a function template as a condition, our |
53 // internal ToBoolean doesn't handle that! | |
54 var result = typeof Constructor === 'undefined' ? | |
55 {} : new (Instantiate(Constructor))(); | |
53 ConfigureTemplateInstance(result, data); | 56 ConfigureTemplateInstance(result, data); |
54 result = %ToFastProperties(result); | 57 result = %ToFastProperties(result); |
55 return result; | 58 return result; |
56 default: | 59 default: |
57 throw 'Unknown API tag <' + tag + '>'; | 60 throw 'Unknown API tag <' + tag + '>'; |
58 } | 61 } |
59 } | 62 } |
60 | 63 |
61 | 64 |
62 function InstantiateFunction(data, name) { | 65 function InstantiateFunction(data, name) { |
63 // We need a reference to kApiFunctionCache in the stack frame | 66 // We need a reference to kApiFunctionCache in the stack frame |
64 // if we need to bail out from a stack overflow. | 67 // if we need to bail out from a stack overflow. |
65 var cache = kApiFunctionCache; | 68 var cache = kApiFunctionCache; |
66 var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset); | 69 var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset); |
67 var isFunctionCached = | 70 var isFunctionCached = |
68 (serialNumber in cache) && (cache[serialNumber] != kUninitialized); | 71 (serialNumber in cache) && (cache[serialNumber] != kUninitialized); |
69 if (!isFunctionCached) { | 72 if (!isFunctionCached) { |
70 try { | 73 try { |
71 cache[serialNumber] = null; | 74 cache[serialNumber] = null; |
72 var fun = %CreateApiFunction(data); | 75 var fun = %CreateApiFunction(data); |
73 if (name) %FunctionSetName(fun, name); | 76 if (name) %FunctionSetName(fun, name); |
74 cache[serialNumber] = fun; | 77 cache[serialNumber] = fun; |
75 var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset); | 78 var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset); |
76 var flags = %GetTemplateField(data, kApiFlagOffset); | 79 var flags = %GetTemplateField(data, kApiFlagOffset); |
77 fun.prototype = prototype ? Instantiate(prototype) : {}; | 80 // Note: Do not directly use an object template as a condition, our |
81 // internal ToBoolean doesn't handle that! | |
82 fun.prototype = typeof prototype ==='undefined' ? | |
Erik Corry
2011/08/10 16:44:36
Missing space after ===
Sven Panne
2011/08/11 07:19:25
Done.
| |
83 {} : Instantiate(prototype); | |
78 if (flags & (1 << kReadOnlyPrototypeBit)) { | 84 if (flags & (1 << kReadOnlyPrototypeBit)) { |
79 %FunctionSetReadOnlyPrototype(fun); | 85 %FunctionSetReadOnlyPrototype(fun); |
80 } | 86 } |
81 %SetProperty(fun.prototype, "constructor", fun, DONT_ENUM); | 87 %SetProperty(fun.prototype, "constructor", fun, DONT_ENUM); |
82 var parent = %GetTemplateField(data, kApiParentTemplateOffset); | 88 var parent = %GetTemplateField(data, kApiParentTemplateOffset); |
83 if (parent) { | 89 // Note: Do not directly use a function template as a condition, our |
90 // internal ToBoolean doesn't handle that! | |
91 if (!(typeof parent ==='undefined')) { | |
Erik Corry
2011/08/10 16:44:36
Ditto
Sven Panne
2011/08/11 07:19:25
Done.
| |
84 var parent_fun = Instantiate(parent); | 92 var parent_fun = Instantiate(parent); |
85 fun.prototype.__proto__ = parent_fun.prototype; | 93 fun.prototype.__proto__ = parent_fun.prototype; |
86 } | 94 } |
87 ConfigureTemplateInstance(fun, data); | 95 ConfigureTemplateInstance(fun, data); |
88 } catch (e) { | 96 } catch (e) { |
89 cache[serialNumber] = kUninitialized; | 97 cache[serialNumber] = kUninitialized; |
90 throw e; | 98 throw e; |
91 } | 99 } |
92 } | 100 } |
93 return cache[serialNumber]; | 101 return cache[serialNumber]; |
(...skipping 11 matching lines...) Expand all Loading... | |
105 var prop_data = properties[i + 2]; | 113 var prop_data = properties[i + 2]; |
106 var attributes = properties[i + 3]; | 114 var attributes = properties[i + 3]; |
107 var value = Instantiate(prop_data, name); | 115 var value = Instantiate(prop_data, name); |
108 %SetProperty(obj, name, value, attributes); | 116 %SetProperty(obj, name, value, attributes); |
109 } | 117 } |
110 } finally { | 118 } finally { |
111 if (requires_access_checks) %EnableAccessChecks(obj); | 119 if (requires_access_checks) %EnableAccessChecks(obj); |
112 } | 120 } |
113 } | 121 } |
114 } | 122 } |
OLD | NEW |