OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "compiler.h" | 31 #include "compiler.h" |
32 #include "contexts.h" | 32 #include "contexts.h" |
33 #include "deoptimizer.h" | 33 #include "deoptimizer.h" |
34 #include "execution.h" | 34 #include "execution.h" |
35 #include "factory.h" | 35 #include "factory.h" |
36 #include "frames-inl.h" | 36 #include "frames-inl.h" |
37 #include "isolate.h" | 37 #include "isolate.h" |
38 #include "list-inl.h" | 38 #include "list-inl.h" |
39 #include "property-details.h" | 39 #include "property-details.h" |
| 40 #include "api.h" |
40 | 41 |
41 namespace v8 { | 42 namespace v8 { |
42 namespace internal { | 43 namespace internal { |
43 | 44 |
44 | 45 |
| 46 static Handle<AccessorInfo> MakeAccessor(Isolate* isolate, |
| 47 Handle<String> name, |
| 48 AccessorGetterCallback getter, |
| 49 AccessorSetterCallback setter, |
| 50 PropertyAttributes attributes) { |
| 51 Factory* factory = isolate->factory(); |
| 52 Handle<ExecutableAccessorInfo> info = factory->NewExecutableAccessorInfo(); |
| 53 info->set_property_attributes(attributes); |
| 54 info->set_all_can_read(true); |
| 55 info->set_all_can_write(true); |
| 56 info->set_prohibits_overwriting(true); |
| 57 info->set_name(*factory->length_string()); |
| 58 info->set_property_attributes(attributes); |
| 59 Handle<Object> get = v8::FromCData(isolate, getter); |
| 60 Handle<Object> set = v8::FromCData(isolate, setter); |
| 61 info->set_getter(*get); |
| 62 if (!(attributes & ReadOnly)) info->set_setter(*set); |
| 63 return info; |
| 64 } |
| 65 |
| 66 |
45 template <class C> | 67 template <class C> |
46 static C* FindInstanceOf(Isolate* isolate, Object* obj) { | 68 static C* FindInstanceOf(Isolate* isolate, Object* obj) { |
47 for (Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype(isolate)) { | 69 for (Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype(isolate)) { |
48 if (Is<C>(cur)) return C::cast(cur); | 70 if (Is<C>(cur)) return C::cast(cur); |
49 } | 71 } |
50 return NULL; | 72 return NULL; |
51 } | 73 } |
52 | 74 |
53 | 75 |
54 // Entry point that never should be called. | 76 // Entry point that never should be called. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 ArrayGetLength, | 247 ArrayGetLength, |
226 ArraySetLength, | 248 ArraySetLength, |
227 0 | 249 0 |
228 }; | 250 }; |
229 | 251 |
230 | 252 |
231 // | 253 // |
232 // Accessors::StringLength | 254 // Accessors::StringLength |
233 // | 255 // |
234 | 256 |
235 | 257 void Accessors::StringLengthGetter( |
236 MaybeObject* Accessors::StringGetLength(Isolate* isolate, | 258 v8::Local<v8::String> name, |
237 Object* object, | 259 const v8::PropertyCallbackInfo<v8::Value>& info) { |
238 void*) { | 260 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
239 Object* value = object; | 261 DisallowHeapAllocation no_allocation; |
240 if (object->IsJSValue()) value = JSValue::cast(object)->value(); | 262 HandleScope scope(isolate); |
241 if (value->IsString()) return Smi::FromInt(String::cast(value)->length()); | 263 Object* value = *Utils::OpenHandle(*info.This()); |
242 // If object is not a string we return 0 to be compatible with WebKit. | 264 Object* result; |
243 // Note: Firefox returns the length of ToString(object). | 265 if (value->IsJSValue()) value = JSValue::cast(value)->value(); |
244 return Smi::FromInt(0); | 266 if (value->IsString()) { |
| 267 result = Smi::FromInt(String::cast(value)->length()); |
| 268 } else { |
| 269 // If object is not a string we return 0 to be compatible with WebKit. |
| 270 // Note: Firefox returns the length of ToString(object). |
| 271 result = Smi::FromInt(0); |
| 272 } |
| 273 info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(result, isolate))); |
245 } | 274 } |
246 | 275 |
247 | 276 |
248 const AccessorDescriptor Accessors::StringLength = { | 277 void Accessors::StringLengthSetter( |
249 StringGetLength, | 278 v8::Local<v8::String> name, |
250 IllegalSetter, | 279 v8::Local<v8::Value> value, |
251 0 | 280 const v8::PropertyCallbackInfo<void>& info) { |
252 }; | 281 UNREACHABLE(); |
| 282 } |
| 283 |
| 284 |
| 285 Handle<AccessorInfo> Accessors::StringLengthInfo( |
| 286 Isolate* isolate, PropertyAttributes attributes) { |
| 287 return MakeAccessor(isolate, |
| 288 isolate->factory()->length_string(), |
| 289 &StringLengthGetter, |
| 290 &StringLengthSetter, |
| 291 attributes); |
| 292 } |
253 | 293 |
254 | 294 |
255 // | 295 // |
256 // Accessors::ScriptSource | 296 // Accessors::ScriptSource |
257 // | 297 // |
258 | 298 |
259 | 299 |
260 MaybeObject* Accessors::ScriptGetSource(Isolate* isolate, | 300 MaybeObject* Accessors::ScriptGetSource(Isolate* isolate, |
261 Object* object, | 301 Object* object, |
262 void*) { | 302 void*) { |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 info->set_data(Smi::FromInt(index)); | 1007 info->set_data(Smi::FromInt(index)); |
968 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 1008 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
969 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 1009 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
970 info->set_getter(*getter); | 1010 info->set_getter(*getter); |
971 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 1011 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
972 return info; | 1012 return info; |
973 } | 1013 } |
974 | 1014 |
975 | 1015 |
976 } } // namespace v8::internal | 1016 } } // namespace v8::internal |
OLD | NEW |