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