OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 | 204 |
205 template<typename To> | 205 template<typename To> |
206 static inline To* CheckedCast(void *from) { | 206 static inline To* CheckedCast(void *from) { |
207 uintptr_t temp = reinterpret_cast<uintptr_t>(from); | 207 uintptr_t temp = reinterpret_cast<uintptr_t>(from); |
208 ASSERT(temp % sizeof(To) == 0); | 208 ASSERT(temp % sizeof(To) == 0); |
209 return reinterpret_cast<To*>(temp); | 209 return reinterpret_cast<To*>(temp); |
210 } | 210 } |
211 | 211 |
212 | 212 |
213 static MaybeObject* PerformCompare(const BitmaskCompareDescriptor& descriptor, | 213 static Handle<Object> PerformCompare(const BitmaskCompareDescriptor& descriptor, |
214 char* ptr, | 214 char* ptr, |
215 Heap* heap) { | 215 Isolate* isolate) { |
216 uint32_t bitmask = descriptor.bitmask; | 216 uint32_t bitmask = descriptor.bitmask; |
217 uint32_t compare_value = descriptor.compare_value; | 217 uint32_t compare_value = descriptor.compare_value; |
218 uint32_t value; | 218 uint32_t value; |
219 switch (descriptor.size) { | 219 switch (descriptor.size) { |
220 case 1: | 220 case 1: |
221 value = static_cast<uint32_t>(*CheckedCast<uint8_t>(ptr)); | 221 value = static_cast<uint32_t>(*CheckedCast<uint8_t>(ptr)); |
222 compare_value &= 0xff; | 222 compare_value &= 0xff; |
223 bitmask &= 0xff; | 223 bitmask &= 0xff; |
224 break; | 224 break; |
225 case 2: | 225 case 2: |
226 value = static_cast<uint32_t>(*CheckedCast<uint16_t>(ptr)); | 226 value = static_cast<uint32_t>(*CheckedCast<uint16_t>(ptr)); |
227 compare_value &= 0xffff; | 227 compare_value &= 0xffff; |
228 bitmask &= 0xffff; | 228 bitmask &= 0xffff; |
229 break; | 229 break; |
230 case 4: | 230 case 4: |
231 value = *CheckedCast<uint32_t>(ptr); | 231 value = *CheckedCast<uint32_t>(ptr); |
232 break; | 232 break; |
233 default: | 233 default: |
234 UNREACHABLE(); | 234 UNREACHABLE(); |
235 return NULL; | 235 return isolate->factory()->undefined_value(); |
236 } | 236 } |
237 return heap->ToBoolean((bitmask & value) == (bitmask & compare_value)); | 237 return isolate->factory()->ToBoolean( |
| 238 (bitmask & value) == (bitmask & compare_value)); |
238 } | 239 } |
239 | 240 |
240 | 241 |
241 static MaybeObject* PerformCompare(const PointerCompareDescriptor& descriptor, | 242 static Handle<Object> PerformCompare(const PointerCompareDescriptor& descriptor, |
242 char* ptr, | 243 char* ptr, |
243 Heap* heap) { | 244 Isolate* isolate) { |
244 uintptr_t compare_value = | 245 uintptr_t compare_value = |
245 reinterpret_cast<uintptr_t>(descriptor.compare_value); | 246 reinterpret_cast<uintptr_t>(descriptor.compare_value); |
246 uintptr_t value = *CheckedCast<uintptr_t>(ptr); | 247 uintptr_t value = *CheckedCast<uintptr_t>(ptr); |
247 return heap->ToBoolean(compare_value == value); | 248 return isolate->factory()->ToBoolean(compare_value == value); |
248 } | 249 } |
249 | 250 |
250 | 251 |
251 static MaybeObject* GetPrimitiveValue( | 252 static Handle<Object> GetPrimitiveValue( |
252 const PrimitiveValueDescriptor& descriptor, | 253 const PrimitiveValueDescriptor& descriptor, |
253 char* ptr, | 254 char* ptr, |
254 Heap* heap) { | 255 Isolate* isolate) { |
255 int32_t int32_value = 0; | 256 int32_t int32_value = 0; |
256 switch (descriptor.data_type) { | 257 switch (descriptor.data_type) { |
257 case kDescriptorInt8Type: | 258 case kDescriptorInt8Type: |
258 int32_value = *CheckedCast<int8_t>(ptr); | 259 int32_value = *CheckedCast<int8_t>(ptr); |
259 break; | 260 break; |
260 case kDescriptorUint8Type: | 261 case kDescriptorUint8Type: |
261 int32_value = *CheckedCast<uint8_t>(ptr); | 262 int32_value = *CheckedCast<uint8_t>(ptr); |
262 break; | 263 break; |
263 case kDescriptorInt16Type: | 264 case kDescriptorInt16Type: |
264 int32_value = *CheckedCast<int16_t>(ptr); | 265 int32_value = *CheckedCast<int16_t>(ptr); |
265 break; | 266 break; |
266 case kDescriptorUint16Type: | 267 case kDescriptorUint16Type: |
267 int32_value = *CheckedCast<uint16_t>(ptr); | 268 int32_value = *CheckedCast<uint16_t>(ptr); |
268 break; | 269 break; |
269 case kDescriptorInt32Type: | 270 case kDescriptorInt32Type: |
270 int32_value = *CheckedCast<int32_t>(ptr); | 271 int32_value = *CheckedCast<int32_t>(ptr); |
271 break; | 272 break; |
272 case kDescriptorUint32Type: { | 273 case kDescriptorUint32Type: { |
273 uint32_t value = *CheckedCast<uint32_t>(ptr); | 274 uint32_t value = *CheckedCast<uint32_t>(ptr); |
274 return heap->NumberFromUint32(value); | 275 AllowHeapAllocation allow_gc; |
| 276 return isolate->factory()->NewNumberFromUint(value); |
275 } | 277 } |
276 case kDescriptorBoolType: { | 278 case kDescriptorBoolType: { |
277 uint8_t byte = *CheckedCast<uint8_t>(ptr); | 279 uint8_t byte = *CheckedCast<uint8_t>(ptr); |
278 return heap->ToBoolean(byte & (0x1 << descriptor.bool_offset)); | 280 return isolate->factory()->ToBoolean( |
| 281 byte & (0x1 << descriptor.bool_offset)); |
279 } | 282 } |
280 case kDescriptorFloatType: { | 283 case kDescriptorFloatType: { |
281 float value = *CheckedCast<float>(ptr); | 284 float value = *CheckedCast<float>(ptr); |
282 return heap->NumberFromDouble(value); | 285 AllowHeapAllocation allow_gc; |
| 286 return isolate->factory()->NewNumber(value); |
283 } | 287 } |
284 case kDescriptorDoubleType: { | 288 case kDescriptorDoubleType: { |
285 double value = *CheckedCast<double>(ptr); | 289 double value = *CheckedCast<double>(ptr); |
286 return heap->NumberFromDouble(value); | 290 AllowHeapAllocation allow_gc; |
| 291 return isolate->factory()->NewNumber(value); |
287 } | 292 } |
288 } | 293 } |
289 return heap->NumberFromInt32(int32_value); | 294 AllowHeapAllocation allow_gc; |
| 295 return isolate->factory()->NewNumberFromInt(int32_value); |
290 } | 296 } |
291 | 297 |
292 | 298 |
293 static MaybeObject* GetDeclaredAccessorProperty(Object* receiver, | 299 static Handle<Object> GetDeclaredAccessorProperty( |
294 DeclaredAccessorInfo* info, | 300 Handle<Object> receiver, |
295 Isolate* isolate) { | 301 Handle<DeclaredAccessorInfo> info, |
296 char* current = reinterpret_cast<char*>(receiver); | 302 Isolate* isolate) { |
| 303 DisallowHeapAllocation no_gc; |
| 304 char* current = reinterpret_cast<char*>(*receiver); |
297 DeclaredAccessorDescriptorIterator iterator(info->descriptor()); | 305 DeclaredAccessorDescriptorIterator iterator(info->descriptor()); |
298 while (true) { | 306 while (true) { |
299 const DeclaredAccessorDescriptorData* data = iterator.Next(); | 307 const DeclaredAccessorDescriptorData* data = iterator.Next(); |
300 switch (data->type) { | 308 switch (data->type) { |
301 case kDescriptorReturnObject: { | 309 case kDescriptorReturnObject: { |
302 ASSERT(iterator.Complete()); | 310 ASSERT(iterator.Complete()); |
303 current = *CheckedCast<char*>(current); | 311 current = *CheckedCast<char*>(current); |
304 return *CheckedCast<Object*>(current); | 312 return handle(*CheckedCast<Object*>(current), isolate); |
305 } | 313 } |
306 case kDescriptorPointerDereference: | 314 case kDescriptorPointerDereference: |
307 ASSERT(!iterator.Complete()); | 315 ASSERT(!iterator.Complete()); |
308 current = *reinterpret_cast<char**>(current); | 316 current = *reinterpret_cast<char**>(current); |
309 break; | 317 break; |
310 case kDescriptorPointerShift: | 318 case kDescriptorPointerShift: |
311 ASSERT(!iterator.Complete()); | 319 ASSERT(!iterator.Complete()); |
312 current += data->pointer_shift_descriptor.byte_offset; | 320 current += data->pointer_shift_descriptor.byte_offset; |
313 break; | 321 break; |
314 case kDescriptorObjectDereference: { | 322 case kDescriptorObjectDereference: { |
315 ASSERT(!iterator.Complete()); | 323 ASSERT(!iterator.Complete()); |
316 Object* object = CheckedCast<Object>(current); | 324 Object* object = CheckedCast<Object>(current); |
317 int field = data->object_dereference_descriptor.internal_field; | 325 int field = data->object_dereference_descriptor.internal_field; |
318 Object* smi = JSObject::cast(object)->GetInternalField(field); | 326 Object* smi = JSObject::cast(object)->GetInternalField(field); |
319 ASSERT(smi->IsSmi()); | 327 ASSERT(smi->IsSmi()); |
320 current = reinterpret_cast<char*>(smi); | 328 current = reinterpret_cast<char*>(smi); |
321 break; | 329 break; |
322 } | 330 } |
323 case kDescriptorBitmaskCompare: | 331 case kDescriptorBitmaskCompare: |
324 ASSERT(iterator.Complete()); | 332 ASSERT(iterator.Complete()); |
325 return PerformCompare(data->bitmask_compare_descriptor, | 333 return PerformCompare(data->bitmask_compare_descriptor, |
326 current, | 334 current, |
327 isolate->heap()); | 335 isolate); |
328 case kDescriptorPointerCompare: | 336 case kDescriptorPointerCompare: |
329 ASSERT(iterator.Complete()); | 337 ASSERT(iterator.Complete()); |
330 return PerformCompare(data->pointer_compare_descriptor, | 338 return PerformCompare(data->pointer_compare_descriptor, |
331 current, | 339 current, |
332 isolate->heap()); | 340 isolate); |
333 case kDescriptorPrimitiveValue: | 341 case kDescriptorPrimitiveValue: |
334 ASSERT(iterator.Complete()); | 342 ASSERT(iterator.Complete()); |
335 return GetPrimitiveValue(data->primitive_value_descriptor, | 343 return GetPrimitiveValue(data->primitive_value_descriptor, |
336 current, | 344 current, |
337 isolate->heap()); | 345 isolate); |
338 } | 346 } |
339 } | 347 } |
340 UNREACHABLE(); | 348 UNREACHABLE(); |
341 return NULL; | 349 return isolate->factory()->undefined_value(); |
342 } | 350 } |
343 | 351 |
344 | 352 |
345 static Handle<Object> GetDeclaredAccessorProperty( | |
346 Handle<Object> receiver, | |
347 Handle<DeclaredAccessorInfo> info, | |
348 Isolate* isolate) { | |
349 CALL_HEAP_FUNCTION(isolate, | |
350 GetDeclaredAccessorProperty(*receiver, *info, isolate), | |
351 Object); | |
352 } | |
353 | |
354 | |
355 Handle<FixedArray> JSObject::EnsureWritableFastElements( | 353 Handle<FixedArray> JSObject::EnsureWritableFastElements( |
356 Handle<JSObject> object) { | 354 Handle<JSObject> object) { |
357 CALL_HEAP_FUNCTION(object->GetIsolate(), | 355 CALL_HEAP_FUNCTION(object->GetIsolate(), |
358 object->EnsureWritableFastElements(), | 356 object->EnsureWritableFastElements(), |
359 FixedArray); | 357 FixedArray); |
360 } | 358 } |
361 | 359 |
362 | 360 |
363 MaybeHandle<Object> JSObject::GetPropertyWithCallback(Handle<JSObject> object, | 361 MaybeHandle<Object> JSObject::GetPropertyWithCallback(Handle<JSObject> object, |
364 Handle<Object> receiver, | 362 Handle<Object> receiver, |
(...skipping 20 matching lines...) Expand all Loading... |
385 Handle<Object> error = | 383 Handle<Object> error = |
386 isolate->factory()->NewTypeError("incompatible_method_receiver", | 384 isolate->factory()->NewTypeError("incompatible_method_receiver", |
387 HandleVector(args, | 385 HandleVector(args, |
388 ARRAY_SIZE(args))); | 386 ARRAY_SIZE(args))); |
389 return isolate->Throw<Object>(error); | 387 return isolate->Throw<Object>(error); |
390 } | 388 } |
391 // TODO(rossberg): Handling symbols in the API requires changing the API, | 389 // TODO(rossberg): Handling symbols in the API requires changing the API, |
392 // so we do not support it for now. | 390 // so we do not support it for now. |
393 if (name->IsSymbol()) return isolate->factory()->undefined_value(); | 391 if (name->IsSymbol()) return isolate->factory()->undefined_value(); |
394 if (structure->IsDeclaredAccessorInfo()) { | 392 if (structure->IsDeclaredAccessorInfo()) { |
395 CALL_HEAP_FUNCTION( | 393 return GetDeclaredAccessorProperty( |
396 isolate, | 394 receiver, |
397 GetDeclaredAccessorProperty(*receiver, | 395 Handle<DeclaredAccessorInfo>::cast(structure), |
398 DeclaredAccessorInfo::cast(*structure), | 396 isolate); |
399 isolate), | |
400 Object); | |
401 } | 397 } |
402 | 398 |
403 Handle<ExecutableAccessorInfo> data = | 399 Handle<ExecutableAccessorInfo> data = |
404 Handle<ExecutableAccessorInfo>::cast(structure); | 400 Handle<ExecutableAccessorInfo>::cast(structure); |
405 v8::AccessorGetterCallback call_fun = | 401 v8::AccessorGetterCallback call_fun = |
406 v8::ToCData<v8::AccessorGetterCallback>(data->getter()); | 402 v8::ToCData<v8::AccessorGetterCallback>(data->getter()); |
407 if (call_fun == NULL) return isolate->factory()->undefined_value(); | 403 if (call_fun == NULL) return isolate->factory()->undefined_value(); |
408 | 404 |
409 Handle<JSObject> self = Handle<JSObject>::cast(receiver); | 405 Handle<JSObject> self = Handle<JSObject>::cast(receiver); |
410 Handle<String> key = Handle<String>::cast(name); | 406 Handle<String> key = Handle<String>::cast(name); |
(...skipping 16079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16490 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16486 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16491 static const char* error_messages_[] = { | 16487 static const char* error_messages_[] = { |
16492 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16488 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16493 }; | 16489 }; |
16494 #undef ERROR_MESSAGES_TEXTS | 16490 #undef ERROR_MESSAGES_TEXTS |
16495 return error_messages_[reason]; | 16491 return error_messages_[reason]; |
16496 } | 16492 } |
16497 | 16493 |
16498 | 16494 |
16499 } } // namespace v8::internal | 16495 } } // namespace v8::internal |
OLD | NEW |