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 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 "use strict"; | 5 "use strict"; |
6 | 6 |
7 // This file contains infrastructure used by the API. See | 7 // This file contains infrastructure used by the API. See |
8 // v8natives.js for an explanation of these files are processed and | 8 // v8natives.js for an explanation of these files are processed and |
9 // loaded. | 9 // loaded. |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 function Instantiate(data, name) { | 23 function Instantiate(data, name) { |
24 if (!%IsTemplate(data)) return data; | 24 if (!%IsTemplate(data)) return data; |
25 var tag = %GetTemplateField(data, kApiTagOffset); | 25 var tag = %GetTemplateField(data, kApiTagOffset); |
26 switch (tag) { | 26 switch (tag) { |
27 case kFunctionTag: | 27 case kFunctionTag: |
28 return InstantiateFunction(data, name); | 28 return InstantiateFunction(data, name); |
29 case kNewObjectTag: | 29 case kNewObjectTag: |
30 var Constructor = %GetTemplateField(data, kApiConstructorOffset); | 30 var Constructor = %GetTemplateField(data, kApiConstructorOffset); |
31 // Note: Do not directly use a function template as a condition, our | 31 // Note: Do not directly use a function template as a condition, our |
32 // internal ToBoolean doesn't handle that! | 32 // internal ToBoolean doesn't handle that! |
33 var result = typeof Constructor === 'undefined' ? | 33 var result; |
34 {} : new (Instantiate(Constructor))(); | 34 if (typeof Constructor === 'undefined') { |
35 ConfigureTemplateInstance(result, data); | 35 result = {}; |
36 result = %ToFastProperties(result); | 36 ConfigureTemplateInstance(result, data); |
| 37 } else { |
| 38 // ConfigureTemplateInstance is implicitly called before calling the API |
| 39 // constructor in HandleApiCall. |
| 40 result = new (Instantiate(Constructor))(); |
| 41 result = %ToFastProperties(result); |
| 42 } |
37 return result; | 43 return result; |
38 default: | 44 default: |
39 throw 'Unknown API tag <' + tag + '>'; | 45 throw 'Unknown API tag <' + tag + '>'; |
40 } | 46 } |
41 } | 47 } |
42 | 48 |
43 | 49 |
44 function InstantiateFunction(data, name) { | 50 function InstantiateFunction(data, name) { |
45 // We need a reference to kApiFunctionCache in the stack frame | 51 // We need a reference to kApiFunctionCache in the stack frame |
46 // if we need to bail out from a stack overflow. | 52 // if we need to bail out from a stack overflow. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // Disable access checks while instantiating the object. | 92 // Disable access checks while instantiating the object. |
87 var requires_access_checks = %DisableAccessChecks(obj); | 93 var requires_access_checks = %DisableAccessChecks(obj); |
88 try { | 94 try { |
89 for (var i = 1; i < properties[0];) { | 95 for (var i = 1; i < properties[0];) { |
90 var length = properties[i]; | 96 var length = properties[i]; |
91 if (length == 3) { | 97 if (length == 3) { |
92 var name = properties[i + 1]; | 98 var name = properties[i + 1]; |
93 var prop_data = properties[i + 2]; | 99 var prop_data = properties[i + 2]; |
94 var attributes = properties[i + 3]; | 100 var attributes = properties[i + 3]; |
95 var value = Instantiate(prop_data, name); | 101 var value = Instantiate(prop_data, name); |
96 %SetProperty(obj, name, value, attributes); | 102 %AddProperty(obj, name, value, attributes); |
97 } else if (length == 4 || length == 5) { | 103 } else if (length == 4 || length == 5) { |
98 // TODO(verwaest): The 5th value used to be access_control. Remove once | 104 // TODO(verwaest): The 5th value used to be access_control. Remove once |
99 // the bindings are updated. | 105 // the bindings are updated. |
100 var name = properties[i + 1]; | 106 var name = properties[i + 1]; |
101 var getter = properties[i + 2]; | 107 var getter = Instantiate(properties[i + 2]); |
102 var setter = properties[i + 3]; | 108 var setter = Instantiate(properties[i + 3]); |
103 var attribute = properties[i + 4]; | 109 var attribute = properties[i + 4]; |
104 %SetAccessorProperty(obj, name, getter, setter, attribute); | 110 %DefineAccessorPropertyUnchecked(obj, name, getter, setter, attribute); |
105 } else { | 111 } else { |
106 throw "Bad properties array"; | 112 throw "Bad properties array"; |
107 } | 113 } |
108 i += length + 1; | 114 i += length + 1; |
109 } | 115 } |
110 } finally { | 116 } finally { |
111 if (requires_access_checks) %EnableAccessChecks(obj); | 117 if (requires_access_checks) %EnableAccessChecks(obj); |
112 } | 118 } |
113 } | 119 } |
OLD | NEW |