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) \ |
| 59 | V(ScriptEvalFromFunctionName) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 60 | V(ObjectPrototype) |
| 61 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 62 | // Accessors contains all predefined proxy accessors. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | |
| 64 | class Accessors : public AllStatic { |
| 65 | public: |
| 66 | // Accessor descriptors. |
| 67 | #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \ |
| 68 | static const AccessorDescriptor name; |
| 69 | ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION) |
| 70 | #undef ACCESSOR_DESCRIPTOR_DECLARATION |
| 71 | |
| 72 | enum DescriptorId { |
| 73 | #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \ |
| 74 | k##name, |
| 75 | ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION) |
| 76 | #undef ACCESSOR_DESCRIPTOR_DECLARATION |
| 77 | descriptorCount |
| 78 | }; |
| 79 | |
| 80 | // Accessor functions called directly from the runtime system. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 81 | MUST_USE_RESULT static MaybeObject* FunctionGetPrototype(Object* object, |
| 82 | void*); |
| 83 | MUST_USE_RESULT static MaybeObject* FunctionSetPrototype(JSObject* object, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 84 | Object* value, |
| 85 | void*); |
| 86 | static MaybeObject* FunctionGetArguments(Object* object, void*); |
| 87 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 88 | // Accessor infos. |
| 89 | static Handle<AccessorInfo> MakeModuleExport( |
| 90 | Handle<String> name, int index, PropertyAttributes attributes); |
| 91 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | private: |
| 93 | // Accessor functions only used through the descriptor. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 94 | static MaybeObject* FunctionGetLength(Object* object, void*); |
| 95 | static MaybeObject* FunctionGetName(Object* object, void*); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 96 | static MaybeObject* FunctionGetCaller(Object* object, void*); |
| 97 | MUST_USE_RESULT static MaybeObject* ArraySetLength(JSObject* object, |
| 98 | Object* value, void*); |
| 99 | static MaybeObject* ArrayGetLength(Object* object, void*); |
| 100 | static MaybeObject* StringGetLength(Object* object, void*); |
| 101 | static MaybeObject* ScriptGetName(Object* object, void*); |
| 102 | static MaybeObject* ScriptGetId(Object* object, void*); |
| 103 | static MaybeObject* ScriptGetSource(Object* object, void*); |
| 104 | static MaybeObject* ScriptGetLineOffset(Object* object, void*); |
| 105 | static MaybeObject* ScriptGetColumnOffset(Object* object, void*); |
| 106 | static MaybeObject* ScriptGetData(Object* object, void*); |
| 107 | static MaybeObject* ScriptGetType(Object* object, void*); |
| 108 | static MaybeObject* ScriptGetCompilationType(Object* object, void*); |
| 109 | static MaybeObject* ScriptGetLineEnds(Object* object, void*); |
| 110 | static MaybeObject* ScriptGetContextData(Object* object, void*); |
| 111 | static MaybeObject* ScriptGetEvalFromScript(Object* object, void*); |
| 112 | static MaybeObject* ScriptGetEvalFromScriptPosition(Object* object, void*); |
| 113 | static MaybeObject* ScriptGetEvalFromFunctionName(Object* object, void*); |
| 114 | static MaybeObject* ObjectGetPrototype(Object* receiver, void*); |
| 115 | static MaybeObject* ObjectSetPrototype(JSObject* receiver, |
| 116 | Object* value, |
| 117 | void*); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 118 | |
| 119 | // Helper functions. |
| 120 | static Object* FlattenNumber(Object* value); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 121 | static MaybeObject* IllegalSetter(JSObject*, Object*, void*); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | static Object* IllegalGetAccessor(Object* object, void*); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 123 | static MaybeObject* ReadOnlySetAccessor(JSObject*, Object* value, void*); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } } // namespace v8::internal |
| 127 | |
| 128 | #endif // V8_ACCESSORS_H_ |