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(false); |
| 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 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 ArrayGetLength, | 248 ArrayGetLength, |
227 ArraySetLength, | 249 ArraySetLength, |
228 0 | 250 0 |
229 }; | 251 }; |
230 | 252 |
231 | 253 |
232 // | 254 // |
233 // Accessors::StringLength | 255 // Accessors::StringLength |
234 // | 256 // |
235 | 257 |
236 | 258 void Accessors::StringLengthGetter( |
237 MaybeObject* Accessors::StringGetLength(Isolate* isolate, | 259 v8::Local<v8::String> name, |
238 Object* object, | 260 const v8::PropertyCallbackInfo<v8::Value>& info) { |
239 void*) { | 261 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
240 Object* value = object; | 262 DisallowHeapAllocation no_allocation; |
241 if (object->IsJSValue()) value = JSValue::cast(object)->value(); | 263 HandleScope scope(isolate); |
242 if (value->IsString()) return Smi::FromInt(String::cast(value)->length()); | 264 Object* value = *Utils::OpenHandle(*info.This()); |
243 // If object is not a string we return 0 to be compatible with WebKit. | 265 Object* result; |
244 // Note: Firefox returns the length of ToString(object). | 266 if (value->IsJSValue()) value = JSValue::cast(value)->value(); |
245 return Smi::FromInt(0); | 267 if (value->IsString()) { |
| 268 result = Smi::FromInt(String::cast(value)->length()); |
| 269 } else { |
| 270 // If object is not a string we return 0 to be compatible with WebKit. |
| 271 // Note: Firefox returns the length of ToString(object). |
| 272 result = Smi::FromInt(0); |
| 273 } |
| 274 info.GetReturnValue().Set(Utils::ToLocal(Handle<Object>(result, isolate))); |
246 } | 275 } |
247 | 276 |
248 | 277 |
249 const AccessorDescriptor Accessors::StringLength = { | 278 void Accessors::StringLengthSetter( |
250 StringGetLength, | 279 v8::Local<v8::String> name, |
251 IllegalSetter, | 280 v8::Local<v8::Value> value, |
252 0 | 281 const v8::PropertyCallbackInfo<void>& info) { |
253 }; | 282 UNREACHABLE(); |
| 283 } |
| 284 |
| 285 |
| 286 Handle<AccessorInfo> Accessors::StringLengthInfo( |
| 287 Isolate* isolate, PropertyAttributes attributes) { |
| 288 return MakeAccessor(isolate, |
| 289 isolate->factory()->length_string(), |
| 290 &StringLengthGetter, |
| 291 &StringLengthSetter, |
| 292 attributes); |
| 293 } |
254 | 294 |
255 | 295 |
256 // | 296 // |
257 // Accessors::ScriptSource | 297 // Accessors::ScriptSource |
258 // | 298 // |
259 | 299 |
260 | 300 |
261 MaybeObject* Accessors::ScriptGetSource(Isolate* isolate, | 301 MaybeObject* Accessors::ScriptGetSource(Isolate* isolate, |
262 Object* object, | 302 Object* object, |
263 void*) { | 303 void*) { |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 info->set_data(Smi::FromInt(index)); | 1008 info->set_data(Smi::FromInt(index)); |
969 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 1009 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
970 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 1010 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
971 info->set_getter(*getter); | 1011 info->set_getter(*getter); |
972 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 1012 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
973 return info; | 1013 return info; |
974 } | 1014 } |
975 | 1015 |
976 | 1016 |
977 } } // namespace v8::internal | 1017 } } // namespace v8::internal |
OLD | NEW |