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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 // This file contains infrastructure used by the API. See | 28 // This file contains infrastructure used by the API. See |
29 // v8natives.js for an explanation of these files are processed and | 29 // v8natives.js for an explanation of these files are processed and |
30 // loaded. | 30 // loaded. |
31 | 31 |
32 | 32 |
33 function CreateDate(time) { | 33 function CreateDate(time) { |
34 var date = new ORIGINAL_DATE(); | 34 var date = new ORIGINAL_DATE(); |
35 date.setTime(time); | 35 date.setTime(time); |
36 return date; | 36 return date; |
37 }; | 37 } |
38 | 38 |
39 | 39 |
40 const kApiFunctionCache = {}; | 40 const kApiFunctionCache = {}; |
41 const functionCache = kApiFunctionCache; | 41 const functionCache = kApiFunctionCache; |
42 | 42 |
43 | 43 |
44 function Instantiate(data) { | 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); | 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 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) { | 61 function InstantiateFunction(data, name) { |
62 var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset); | 62 var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset); |
63 if (!(serialNumber in kApiFunctionCache)) { | 63 if (!(serialNumber in kApiFunctionCache)) { |
64 kApiFunctionCache[serialNumber] = null; | 64 kApiFunctionCache[serialNumber] = null; |
65 var fun = %CreateApiFunction(data); | 65 var fun = %CreateApiFunction(data); |
| 66 if (name) %FunctionSetName(fun, name); |
66 kApiFunctionCache[serialNumber] = fun; | 67 kApiFunctionCache[serialNumber] = fun; |
67 var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset); | 68 var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset); |
68 fun.prototype = prototype ? Instantiate(prototype) : {}; | 69 fun.prototype = prototype ? Instantiate(prototype) : {}; |
69 %AddProperty(fun.prototype, "constructor", fun, DONT_ENUM); | 70 %AddProperty(fun.prototype, "constructor", fun, DONT_ENUM); |
70 var parent = %GetTemplateField(data, kApiParentTemplateOffset); | 71 var parent = %GetTemplateField(data, kApiParentTemplateOffset); |
71 if (parent) { | 72 if (parent) { |
72 var parent_fun = Instantiate(parent); | 73 var parent_fun = Instantiate(parent); |
73 fun.prototype.__proto__ = parent_fun.prototype; | 74 fun.prototype.__proto__ = parent_fun.prototype; |
74 } | 75 } |
75 ConfigureTemplateInstance(fun, data); | 76 ConfigureTemplateInstance(fun, data); |
76 } | 77 } |
77 return kApiFunctionCache[serialNumber]; | 78 return kApiFunctionCache[serialNumber]; |
78 }; | 79 } |
79 | 80 |
80 | 81 |
81 function ConfigureTemplateInstance(obj, data) { | 82 function ConfigureTemplateInstance(obj, data) { |
82 var properties = %GetTemplateField(data, kApiPropertyListOffset); | 83 var properties = %GetTemplateField(data, kApiPropertyListOffset); |
83 if (properties) { | 84 if (properties) { |
84 for (var i = 0; i < properties[0]; i += 3) { | 85 for (var i = 0; i < properties[0]; i += 3) { |
85 var name = properties[i + 1]; | 86 var name = properties[i + 1]; |
86 var prop_data = properties[i + 2]; | 87 var prop_data = properties[i + 2]; |
87 var attributes = properties[i + 3]; | 88 var attributes = properties[i + 3]; |
88 var value = Instantiate(prop_data); | 89 var value = Instantiate(prop_data, name); |
89 %SetProperty(obj, name, value, attributes); | 90 %SetProperty(obj, name, value, attributes); |
90 } | 91 } |
91 } | 92 } |
92 }; | 93 } |
OLD | NEW |