OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 3294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3305 "o0_mirror.property('y').value().value()")->Int32Value()); | 3305 "o0_mirror.property('y').value().value()")->Int32Value()); |
3306 CHECK_EQ(2, CompileRun( | 3306 CHECK_EQ(2, CompileRun( |
3307 "o0_mirror.property('z').value().value()")->Int32Value()); | 3307 "o0_mirror.property('z').value().value()")->Int32Value()); |
3308 CHECK(CompileRun("o0_mirror.property('u').isUndefined()")->BooleanValue()); | 3308 CHECK(CompileRun("o0_mirror.property('u').isUndefined()")->BooleanValue()); |
3309 | 3309 |
3310 // The prototype (__proto__) for o0 should be o3 as o1 and o2 are hidden. | 3310 // The prototype (__proto__) for o0 should be o3 as o1 and o2 are hidden. |
3311 CHECK(CompileRun("o0_mirror.protoObject() == o3_mirror")->BooleanValue()); | 3311 CHECK(CompileRun("o0_mirror.protoObject() == o3_mirror")->BooleanValue()); |
3312 } | 3312 } |
3313 | 3313 |
3314 | 3314 |
| 3315 static v8::Handle<v8::Value> ProtperyXNativeGetter( |
| 3316 v8::Local<v8::String> property, const v8::AccessorInfo& info) { |
| 3317 return v8::Integer::New(10); |
| 3318 } |
| 3319 |
| 3320 |
| 3321 TEST(NativeGetterPropertyMirror) { |
| 3322 // Create a V8 environment with debug access. |
| 3323 v8::HandleScope scope; |
| 3324 DebugLocalContext env; |
| 3325 env.ExposeDebug(); |
| 3326 |
| 3327 v8::Handle<v8::String> name = v8::String::New("x"); |
| 3328 // Create object with named accessor. |
| 3329 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(); |
| 3330 named->SetAccessor(name, &ProtperyXNativeGetter, NULL, |
| 3331 v8::Handle<v8::Value>(), v8::DEFAULT, v8::None); |
| 3332 |
| 3333 // Create object with named property getter. |
| 3334 env->Global()->Set(v8::String::New("instance"), named->NewInstance()); |
| 3335 CHECK_EQ(10, CompileRun("instance.x")->Int32Value()); |
| 3336 |
| 3337 // Get mirror for the object with property getter. |
| 3338 CompileRun("instance_mirror = debug.MakeMirror(instance);"); |
| 3339 CHECK(CompileRun( |
| 3340 "instance_mirror instanceof debug.ObjectMirror")->BooleanValue()); |
| 3341 |
| 3342 CompileRun("named_names = instance_mirror.propertyNames();"); |
| 3343 CHECK_EQ(1, CompileRun("named_names.length")->Int32Value()); |
| 3344 CHECK(CompileRun("named_names[0] == 'x'")->BooleanValue()); |
| 3345 CHECK(CompileRun( |
| 3346 "instance_mirror.property('x').value().isNumber()")->BooleanValue()); |
| 3347 CHECK(CompileRun( |
| 3348 "instance_mirror.property('x').value().value() == 10")->BooleanValue()); |
| 3349 } |
| 3350 |
| 3351 |
| 3352 static v8::Handle<v8::Value> ProtperyXNativeGetterThrowingError( |
| 3353 v8::Local<v8::String> property, const v8::AccessorInfo& info) { |
| 3354 return CompileRun("throw new Error('Error message');"); |
| 3355 } |
| 3356 |
| 3357 |
| 3358 TEST(NativeGetterThrowingErrorPropertyMirror) { |
| 3359 // Create a V8 environment with debug access. |
| 3360 v8::HandleScope scope; |
| 3361 DebugLocalContext env; |
| 3362 env.ExposeDebug(); |
| 3363 |
| 3364 v8::Handle<v8::String> name = v8::String::New("x"); |
| 3365 // Create object with named accessor. |
| 3366 v8::Handle<v8::ObjectTemplate> named = v8::ObjectTemplate::New(); |
| 3367 named->SetAccessor(name, &ProtperyXNativeGetterThrowingError, NULL, |
| 3368 v8::Handle<v8::Value>(), v8::DEFAULT, v8::None); |
| 3369 |
| 3370 // Create object with named property getter. |
| 3371 env->Global()->Set(v8::String::New("instance"), named->NewInstance()); |
| 3372 |
| 3373 // Get mirror for the object with property getter. |
| 3374 CompileRun("instance_mirror = debug.MakeMirror(instance);"); |
| 3375 CHECK(CompileRun( |
| 3376 "instance_mirror instanceof debug.ObjectMirror")->BooleanValue()); |
| 3377 CompileRun("named_names = instance_mirror.propertyNames();"); |
| 3378 CHECK_EQ(1, CompileRun("named_names.length")->Int32Value()); |
| 3379 CHECK(CompileRun("named_names[0] == 'x'")->BooleanValue()); |
| 3380 CHECK(CompileRun( |
| 3381 "instance_mirror.property('x').value().isError()")->BooleanValue()); |
| 3382 |
| 3383 // Check that the message is that passed to the Error constructor. |
| 3384 CHECK(CompileRun( |
| 3385 "instance_mirror.property('x').value().message() == 'Error message'")-> |
| 3386 BooleanValue()); |
| 3387 } |
| 3388 |
| 3389 |
| 3390 |
3315 // Multithreaded tests of JSON debugger protocol | 3391 // Multithreaded tests of JSON debugger protocol |
3316 | 3392 |
3317 // Support classes | 3393 // Support classes |
3318 | 3394 |
3319 // Copies a C string to a 16-bit string. Does not check for buffer overflow. | 3395 // Copies a C string to a 16-bit string. Does not check for buffer overflow. |
3320 // Does not use the V8 engine to convert strings, so it can be used | 3396 // Does not use the V8 engine to convert strings, so it can be used |
3321 // in any thread. Returns the length of the string. | 3397 // in any thread. Returns the length of the string. |
3322 int AsciiToUtf16(const char* input_buffer, uint16_t* output_buffer) { | 3398 int AsciiToUtf16(const char* input_buffer, uint16_t* output_buffer) { |
3323 int i; | 3399 int i; |
3324 for (i = 0; input_buffer[i] != '\0'; ++i) { | 3400 for (i = 0; input_buffer[i] != '\0'; ++i) { |
(...skipping 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4990 v8::Local<v8::Function> f = | 5066 v8::Local<v8::Function> f = |
4991 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 5067 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
4992 f->Call(env->Global(), 0, NULL); | 5068 f->Call(env->Global(), 0, NULL); |
4993 | 5069 |
4994 // Setting message handler to NULL should cause debugger unload. | 5070 // Setting message handler to NULL should cause debugger unload. |
4995 v8::Debug::SetMessageHandler2(NULL); | 5071 v8::Debug::SetMessageHandler2(NULL); |
4996 CheckDebuggerUnloaded(); | 5072 CheckDebuggerUnloaded(); |
4997 | 5073 |
4998 CHECK_EQ(1, exception_event_count); | 5074 CHECK_EQ(1, exception_event_count); |
4999 } | 5075 } |
OLD | NEW |