yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_ACCESSORS_H_ |
| 29 | #define V8_ACCESSORS_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 32 | #include "v8globals.h" |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 33 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 34 | namespace v8 { |
| 35 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | |
| 37 | // The list of accessor descriptors. This is a second-order macro |
| 38 | // taking a macro to be applied to all accessor descriptor names. |
| 39 | #define ACCESSOR_DESCRIPTOR_LIST(V) \ |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 40 | V(FunctionPrototype) \ |
| 41 | V(FunctionLength) \ |
| 42 | V(FunctionName) \ |
| 43 | V(FunctionArguments) \ |
| 44 | V(FunctionCaller) \ |
| 45 | V(ArrayLength) \ |
| 46 | V(StringLength) \ |
| 47 | V(ScriptSource) \ |
| 48 | V(ScriptName) \ |
| 49 | V(ScriptId) \ |
| 50 | V(ScriptLineOffset) \ |
| 51 | V(ScriptColumnOffset) \ |
| 52 | V(ScriptData) \ |
| 53 | V(ScriptType) \ |
| 54 | V(ScriptCompilationType) \ |
| 55 | V(ScriptLineEnds) \ |
| 56 | V(ScriptContextData) \ |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 57 | V(ScriptEvalFromScript) \ |
| 58 | V(ScriptEvalFromScriptPosition) \ |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 59 | V(ScriptEvalFromFunctionName) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 60 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 61 | // Accessors contains all predefined proxy accessors. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 62 | |
| 63 | class Accessors : public AllStatic { |
| 64 | public: |
| 65 | // Accessor descriptors. |
| 66 | #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \ |
| 67 | static const AccessorDescriptor name; |
| 68 | ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION) |
| 69 | #undef ACCESSOR_DESCRIPTOR_DECLARATION |
| 70 | |
| 71 | enum DescriptorId { |
| 72 | #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \ |
| 73 | k##name, |
| 74 | ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION) |
| 75 | #undef ACCESSOR_DESCRIPTOR_DECLARATION |
| 76 | descriptorCount |
| 77 | }; |
| 78 | |
| 79 | // Accessor functions called directly from the runtime system. |
rossberg@chromium.org | ebeba02 | 2013-08-19 09:36:44 +0000 | [diff] [blame] | 80 | static Handle<Object> FunctionSetPrototype(Handle<JSFunction> object, |
| 81 | Handle<Object> value); |
| 82 | static Handle<Object> FunctionGetPrototype(Handle<JSFunction> object); |
| 83 | static Handle<Object> FunctionGetArguments(Handle<JSFunction> object); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 84 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 85 | // Accessor infos. |
| 86 | static Handle<AccessorInfo> MakeModuleExport( |
| 87 | Handle<String> name, int index, PropertyAttributes attributes); |
| 88 | |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 89 | // Returns true for properties that are accessors to object fields. |
| 90 | // If true, *object_offset contains offset of object field. |
| 91 | static bool IsJSObjectFieldAccessor( |
| 92 | Handle<Map> map, Handle<String> name, |
| 93 | int* object_offset); |
| 94 | |
| 95 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 96 | private: |
| 97 | // Accessor functions only used through the descriptor. |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 98 | static MaybeObject* FunctionSetPrototype(Isolate* isolate, |
| 99 | JSObject* object, |
| 100 | Object*, |
| 101 | void*); |
| 102 | static MaybeObject* FunctionGetPrototype(Isolate* isolate, |
| 103 | Object* object, |
| 104 | void*); |
| 105 | static MaybeObject* FunctionGetLength(Isolate* isolate, |
| 106 | Object* object, |
| 107 | void*); |
| 108 | static MaybeObject* FunctionGetName(Isolate* isolate, Object* object, void*); |
| 109 | static MaybeObject* FunctionGetArguments(Isolate* isolate, |
| 110 | Object* object, |
| 111 | void*); |
| 112 | static MaybeObject* FunctionGetCaller(Isolate* isolate, |
| 113 | Object* object, |
| 114 | void*); |
| 115 | static MaybeObject* ArraySetLength(Isolate* isolate, |
| 116 | JSObject* object, |
| 117 | Object*, |
| 118 | void*); |
| 119 | static MaybeObject* ArrayGetLength(Isolate* isolate, Object* object, void*); |
| 120 | static MaybeObject* StringGetLength(Isolate* isolate, Object* object, void*); |
| 121 | static MaybeObject* ScriptGetName(Isolate* isolate, Object* object, void*); |
| 122 | static MaybeObject* ScriptGetId(Isolate* isolate, Object* object, void*); |
| 123 | static MaybeObject* ScriptGetSource(Isolate* isolate, Object* object, void*); |
| 124 | static MaybeObject* ScriptGetLineOffset(Isolate* isolate, |
| 125 | Object* object, |
| 126 | void*); |
| 127 | static MaybeObject* ScriptGetColumnOffset(Isolate* isolate, |
| 128 | Object* object, |
| 129 | void*); |
| 130 | static MaybeObject* ScriptGetData(Isolate* isolate, Object* object, void*); |
| 131 | static MaybeObject* ScriptGetType(Isolate* isolate, Object* object, void*); |
| 132 | static MaybeObject* ScriptGetCompilationType(Isolate* isolate, |
| 133 | Object* object, |
| 134 | void*); |
| 135 | static MaybeObject* ScriptGetLineEnds(Isolate* isolate, |
| 136 | Object* object, |
| 137 | void*); |
| 138 | static MaybeObject* ScriptGetContextData(Isolate* isolate, |
| 139 | Object* object, |
| 140 | void*); |
| 141 | static MaybeObject* ScriptGetEvalFromScript(Isolate* isolate, |
| 142 | Object* object, |
| 143 | void*); |
| 144 | static MaybeObject* ScriptGetEvalFromScriptPosition(Isolate* isolate, |
| 145 | Object* object, |
| 146 | void*); |
| 147 | static MaybeObject* ScriptGetEvalFromFunctionName(Isolate* isolate, |
| 148 | Object* object, |
| 149 | void*); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 150 | |
| 151 | // Helper functions. |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 152 | static Object* FlattenNumber(Isolate* isolate, Object* value); |
| 153 | static MaybeObject* IllegalSetter(Isolate* isolate, |
| 154 | JSObject*, |
| 155 | Object*, |
| 156 | void*); |
| 157 | static Object* IllegalGetAccessor(Isolate* isolate, Object* object, void*); |
| 158 | static MaybeObject* ReadOnlySetAccessor(Isolate* isolate, |
| 159 | JSObject*, |
| 160 | Object* value, |
| 161 | void*); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | } } // namespace v8::internal |
| 165 | |
| 166 | #endif // V8_ACCESSORS_H_ |