OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 FACTORY->NewFunction(FACTORY->function_symbol(), FACTORY->null_value()); | 144 FACTORY->NewFunction(FACTORY->function_symbol(), FACTORY->null_value()); |
145 // Force the creation of an initial map and set the code to | 145 // Force the creation of an initial map and set the code to |
146 // something empty. | 146 // something empty. |
147 FACTORY->NewJSObject(function); | 147 FACTORY->NewJSObject(function); |
148 function->ReplaceCode(Isolate::Current()->builtins()->builtin( | 148 function->ReplaceCode(Isolate::Current()->builtins()->builtin( |
149 Builtins::kEmptyFunction)); | 149 Builtins::kEmptyFunction)); |
150 // Patch the map to have an accessor for "get". | 150 // Patch the map to have an accessor for "get". |
151 Handle<Map> map(function->initial_map()); | 151 Handle<Map> map(function->initial_map()); |
152 Handle<DescriptorArray> instance_descriptors(map->instance_descriptors()); | 152 Handle<DescriptorArray> instance_descriptors(map->instance_descriptors()); |
153 Handle<Foreign> foreign = FACTORY->NewForeign(&kDescriptor); | 153 Handle<Foreign> foreign = FACTORY->NewForeign(&kDescriptor); |
154 instance_descriptors = FACTORY->CopyAppendForeignDescriptor( | 154 Handle<String> name = |
155 instance_descriptors, | 155 FACTORY->NewStringFromAscii(Vector<const char>("get", 3)); |
156 FACTORY->NewStringFromAscii(Vector<const char>("get", 3)), | 156 ASSERT(instance_descriptors->IsEmpty()); |
157 foreign, | 157 |
158 static_cast<PropertyAttributes>(0)); | 158 Handle<DescriptorArray> new_descriptors = FACTORY->NewDescriptorArray(1); |
159 map->set_instance_descriptors(*instance_descriptors); | 159 |
| 160 v8::internal::DescriptorArray::WhitenessWitness witness(*new_descriptors); |
| 161 |
| 162 CallbacksDescriptor d(*name, |
| 163 *foreign, |
| 164 static_cast<PropertyAttributes>(0), |
| 165 v8::internal::PropertyDetails::kInitialIndex); |
| 166 new_descriptors->Set(0, &d, witness); |
| 167 new_descriptors->SetLastAdded(0); |
| 168 |
| 169 map->set_instance_descriptors(*new_descriptors); |
160 // Add the Foo constructor the global object. | 170 // Add the Foo constructor the global object. |
161 env->Global()->Set(v8::String::New("Foo"), v8::Utils::ToLocal(function)); | 171 env->Global()->Set(v8::String::New("Foo"), v8::Utils::ToLocal(function)); |
162 // Call the accessor through JavaScript. | 172 // Call the accessor through JavaScript. |
163 v8::Handle<v8::Value> result = | 173 v8::Handle<v8::Value> result = |
164 v8::Script::Compile(v8::String::New("(new Foo).get"))->Run(); | 174 v8::Script::Compile(v8::String::New("(new Foo).get"))->Run(); |
165 CHECK_EQ(42, result->Int32Value()); | 175 CHECK_EQ(42, result->Int32Value()); |
166 env->Exit(); | 176 env->Exit(); |
167 } | 177 } |
168 | 178 |
169 | 179 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 blocks[index] = blocks.RemoveLast(); | 239 blocks[index] = blocks.RemoveLast(); |
230 } else { | 240 } else { |
231 blocks.RemoveLast(); | 241 blocks.RemoveLast(); |
232 } | 242 } |
233 } | 243 } |
234 } | 244 } |
235 | 245 |
236 code_range->TearDown(); | 246 code_range->TearDown(); |
237 delete code_range; | 247 delete code_range; |
238 } | 248 } |
OLD | NEW |