| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/assembler.h" | 5 #include "vm/assembler.h" |
| 6 #include "vm/bigint_operations.h" | 6 #include "vm/bigint_operations.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 EXPECT(abce.CompareTo(monkey_face) < 0); | 325 EXPECT(abce.CompareTo(monkey_face) < 0); |
| 326 EXPECT(abcd.CompareTo(domino) < 0); | 326 EXPECT(abcd.CompareTo(domino) < 0); |
| 327 EXPECT(abce.CompareTo(domino) < 0); | 327 EXPECT(abce.CompareTo(domino) < 0); |
| 328 EXPECT(domino.CompareTo(abcd) > 0); | 328 EXPECT(domino.CompareTo(abcd) > 0); |
| 329 EXPECT(domino.CompareTo(abcd) > 0); | 329 EXPECT(domino.CompareTo(abcd) > 0); |
| 330 EXPECT(monkey_face.CompareTo(abce) > 0); | 330 EXPECT(monkey_face.CompareTo(abce) > 0); |
| 331 EXPECT(monkey_face.CompareTo(abce) > 0); | 331 EXPECT(monkey_face.CompareTo(abce) > 0); |
| 332 } | 332 } |
| 333 | 333 |
| 334 | 334 |
| 335 TEST_CASE(StringEncodeURI) { |
| 336 const char* kInput = |
| 337 "file:///usr/local/johnmccutchan/workspace/dart-repo/dart/test.dart"; |
| 338 const char* kOutput = |
| 339 "file%3A%2F%2F%2Fusr%2Flocal%2Fjohnmccutchan%2Fworkspace%2F" |
| 340 "dart-repo%2Fdart%2Ftest.dart"; |
| 341 const String& input = String::Handle(String::New(kInput)); |
| 342 const String& output = String::Handle(String::New(kOutput)); |
| 343 const String& encoded = String::Handle(String::EncodeURI(input)); |
| 344 EXPECT(output.Equals(encoded)); |
| 345 } |
| 346 |
| 347 |
| 348 TEST_CASE(StringDecodeURI) { |
| 349 const char* kOutput = |
| 350 "file:///usr/local/johnmccutchan/workspace/dart-repo/dart/test.dart"; |
| 351 const char* kInput = |
| 352 "file%3A%2F%2F%2Fusr%2Flocal%2Fjohnmccutchan%2Fworkspace%2F" |
| 353 "dart-repo%2Fdart%2Ftest.dart"; |
| 354 const String& input = String::Handle(String::New(kInput)); |
| 355 const String& output = String::Handle(String::New(kOutput)); |
| 356 const String& decoded = String::Handle(String::DecodeURI(input)); |
| 357 EXPECT(output.Equals(decoded)); |
| 358 } |
| 359 |
| 360 |
| 335 TEST_CASE(Mint) { | 361 TEST_CASE(Mint) { |
| 336 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot | 362 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot |
| 337 // be allocated if it does fit into a Smi. | 363 // be allocated if it does fit into a Smi. |
| 338 #if !defined(ARCH_IS_64_BIT) | 364 #if !defined(ARCH_IS_64_BIT) |
| 339 { Mint& med = Mint::Handle(); | 365 { Mint& med = Mint::Handle(); |
| 340 EXPECT(med.IsNull()); | 366 EXPECT(med.IsNull()); |
| 341 int64_t v = DART_2PART_UINT64_C(1, 0); | 367 int64_t v = DART_2PART_UINT64_C(1, 0); |
| 342 med ^= Integer::New(v); | 368 med ^= Integer::New(v); |
| 343 EXPECT_EQ(v, med.value()); | 369 EXPECT_EQ(v, med.value()); |
| 344 const String& smi_str = String::Handle(String::New("1")); | 370 const String& smi_str = String::Handle(String::New("1")); |
| (...skipping 2397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2742 EXPECT(!Field::IsSetterName(getter_f)); | 2768 EXPECT(!Field::IsSetterName(getter_f)); |
| 2743 EXPECT(!Field::IsGetterName(setter_f)); | 2769 EXPECT(!Field::IsGetterName(setter_f)); |
| 2744 EXPECT(Field::IsSetterName(setter_f)); | 2770 EXPECT(Field::IsSetterName(setter_f)); |
| 2745 EXPECT_STREQ(f.ToCString(), | 2771 EXPECT_STREQ(f.ToCString(), |
| 2746 String::Handle(Field::NameFromGetter(getter_f)).ToCString()); | 2772 String::Handle(Field::NameFromGetter(getter_f)).ToCString()); |
| 2747 EXPECT_STREQ(f.ToCString(), | 2773 EXPECT_STREQ(f.ToCString(), |
| 2748 String::Handle(Field::NameFromSetter(setter_f)).ToCString()); | 2774 String::Handle(Field::NameFromSetter(setter_f)).ToCString()); |
| 2749 } | 2775 } |
| 2750 | 2776 |
| 2751 | 2777 |
| 2778 |
| 2779 |
| 2752 // Expose helper function from object.cc for testing. | 2780 // Expose helper function from object.cc for testing. |
| 2753 bool EqualsIgnoringPrivate(const String& name, const String& private_name); | 2781 bool EqualsIgnoringPrivate(const String& name, const String& private_name); |
| 2754 | 2782 |
| 2755 | 2783 |
| 2756 TEST_CASE(EqualsIgnoringPrivate) { | 2784 TEST_CASE(EqualsIgnoringPrivate) { |
| 2757 String& mangled_name = String::Handle(); | 2785 String& mangled_name = String::Handle(); |
| 2758 String& bare_name = String::Handle(); | 2786 String& bare_name = String::Handle(); |
| 2759 | 2787 |
| 2760 // Simple matches. | 2788 // Simple matches. |
| 2761 mangled_name = OneByteString::New("foo"); | 2789 mangled_name = OneByteString::New("foo"); |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3384 | 3412 |
| 3385 | 3413 |
| 3386 static RawClass* GetClass(const Library& lib, const char* name) { | 3414 static RawClass* GetClass(const Library& lib, const char* name) { |
| 3387 const Class& cls = Class::Handle( | 3415 const Class& cls = Class::Handle( |
| 3388 lib.LookupClass(String::Handle(Symbols::New(name)))); | 3416 lib.LookupClass(String::Handle(Symbols::New(name)))); |
| 3389 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 3417 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
| 3390 return cls.raw(); | 3418 return cls.raw(); |
| 3391 } | 3419 } |
| 3392 | 3420 |
| 3393 | 3421 |
| 3422 TEST_CASE(FindFieldIndex) { |
| 3423 const char* kScriptChars = |
| 3424 "class A {\n" |
| 3425 " var a;\n" |
| 3426 " var b;\n" |
| 3427 "}\n" |
| 3428 "class B {\n" |
| 3429 " var d;\n" |
| 3430 "}\n" |
| 3431 "test() {\n" |
| 3432 " new A();\n" |
| 3433 " new B();\n" |
| 3434 "}"; |
| 3435 Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3436 EXPECT_VALID(h_lib); |
| 3437 Dart_Handle result = Dart_Invoke(h_lib, NewString("test"), 0, NULL); |
| 3438 EXPECT_VALID(result); |
| 3439 Library& lib = Library::Handle(); |
| 3440 lib ^= Api::UnwrapHandle(h_lib); |
| 3441 EXPECT(!lib.IsNull()); |
| 3442 const Class& class_a = Class::Handle(GetClass(lib, "A")); |
| 3443 const Array& class_a_fields = Array::Handle(class_a.fields()); |
| 3444 const Class& class_b = Class::Handle(GetClass(lib, "B")); |
| 3445 const Field& field_a = Field::Handle(GetField(class_a, "a")); |
| 3446 const Field& field_b = Field::Handle(GetField(class_a, "b")); |
| 3447 const Field& field_d = Field::Handle(GetField(class_b, "d")); |
| 3448 intptr_t field_a_index = class_a.FindFieldIndex(field_a); |
| 3449 intptr_t field_b_index = class_a.FindFieldIndex(field_b); |
| 3450 intptr_t field_d_index = class_a.FindFieldIndex(field_d); |
| 3451 // Valid index. |
| 3452 EXPECT_GE(field_a_index, 0); |
| 3453 // Valid index. |
| 3454 EXPECT_GE(field_b_index, 0); |
| 3455 // Invalid index. |
| 3456 EXPECT_EQ(field_d_index, -1); |
| 3457 Field& field_a_from_index = Field::Handle(); |
| 3458 field_a_from_index ^= class_a_fields.At(field_a_index); |
| 3459 ASSERT(!field_a_from_index.IsNull()); |
| 3460 // Same field. |
| 3461 EXPECT_EQ(field_a.raw(), field_a_from_index.raw()); |
| 3462 Field& field_b_from_index = Field::Handle(); |
| 3463 field_b_from_index ^= class_a_fields.At(field_b_index); |
| 3464 ASSERT(!field_b_from_index.IsNull()); |
| 3465 // Same field. |
| 3466 EXPECT_EQ(field_b.raw(), field_b_from_index.raw()); |
| 3467 } |
| 3468 |
| 3469 |
| 3470 TEST_CASE(FindFunctionIndex) { |
| 3471 const char* kScriptChars = |
| 3472 "class A {\n" |
| 3473 " void a() {}\n" |
| 3474 " void b() {}\n" |
| 3475 "}\n" |
| 3476 "class B {\n" |
| 3477 " dynamic d() {}\n" |
| 3478 "}\n" |
| 3479 "test() {\n" |
| 3480 " new A();\n" |
| 3481 " new B();\n" |
| 3482 "}"; |
| 3483 Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3484 EXPECT_VALID(h_lib); |
| 3485 Dart_Handle result = Dart_Invoke(h_lib, NewString("test"), 0, NULL); |
| 3486 EXPECT_VALID(result); |
| 3487 Library& lib = Library::Handle(); |
| 3488 lib ^= Api::UnwrapHandle(h_lib); |
| 3489 EXPECT(!lib.IsNull()); |
| 3490 const Class& class_a = Class::Handle(GetClass(lib, "A")); |
| 3491 const Array& class_a_funcs = Array::Handle(class_a.functions()); |
| 3492 const Class& class_b = Class::Handle(GetClass(lib, "B")); |
| 3493 const Function& func_a = Function::Handle(GetFunction(class_a, "a")); |
| 3494 const Function& func_b = Function::Handle(GetFunction(class_a, "b")); |
| 3495 const Function& func_d = Function::Handle(GetFunction(class_b, "d")); |
| 3496 intptr_t func_a_index = class_a.FindFunctionIndex(func_a); |
| 3497 intptr_t func_b_index = class_a.FindFunctionIndex(func_b); |
| 3498 intptr_t func_d_index = class_a.FindFunctionIndex(func_d); |
| 3499 // Valid index. |
| 3500 EXPECT_GE(func_a_index, 0); |
| 3501 // Valid index. |
| 3502 EXPECT_GE(func_b_index, 0); |
| 3503 // Invalid index. |
| 3504 EXPECT_EQ(func_d_index, -1); |
| 3505 Function& func_a_from_index = Function::Handle(); |
| 3506 func_a_from_index ^= class_a_funcs.At(func_a_index); |
| 3507 ASSERT(!func_a_from_index.IsNull()); |
| 3508 // Same function. |
| 3509 EXPECT_EQ(func_a.raw(), func_a_from_index.raw()); |
| 3510 Function& func_b_from_index = Function::Handle(); |
| 3511 func_b_from_index ^= class_a_funcs.At(func_b_index); |
| 3512 ASSERT(!func_b_from_index.IsNull()); |
| 3513 // Same function. |
| 3514 EXPECT_EQ(func_b.raw(), func_b_from_index.raw()); |
| 3515 } |
| 3516 |
| 3517 |
| 3518 TEST_CASE(FindClosureIndex) { |
| 3519 // Allocate the class first. |
| 3520 const String& class_name = String::Handle(Symbols::New("MyClass")); |
| 3521 const Script& script = Script::Handle(); |
| 3522 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); |
| 3523 const Array& functions = Array::Handle(Array::New(1)); |
| 3524 |
| 3525 Function& parent = Function::Handle(); |
| 3526 const String& parent_name = String::Handle(Symbols::New("foo_papa")); |
| 3527 parent = Function::New(parent_name, RawFunction::kRegularFunction, |
| 3528 false, false, false, false, false, cls, 0); |
| 3529 functions.SetAt(0, parent); |
| 3530 cls.SetFunctions(functions); |
| 3531 |
| 3532 Function& function = Function::Handle(); |
| 3533 const String& function_name = String::Handle(Symbols::New("foo")); |
| 3534 function = Function::NewClosureFunction(function_name, parent, 0); |
| 3535 // Add closure function to class. |
| 3536 cls.AddClosureFunction(function); |
| 3537 |
| 3538 // Token position 0 should return a valid index. |
| 3539 intptr_t good_closure_index = cls.FindClosureIndex(0); |
| 3540 EXPECT_GE(good_closure_index, 0); |
| 3541 // Token position 1 should return an invalid index. |
| 3542 intptr_t bad_closure_index = cls.FindClosureIndex(1); |
| 3543 EXPECT_EQ(bad_closure_index, -1); |
| 3544 |
| 3545 // Retrieve closure function via index. |
| 3546 const GrowableObjectArray& closures = GrowableObjectArray::Handle( |
| 3547 cls.closures()); |
| 3548 Function& func_from_index = Function::Handle(); |
| 3549 func_from_index ^= closures.At(good_closure_index); |
| 3550 |
| 3551 // Same closure function. |
| 3552 EXPECT_EQ(func_from_index.raw(), function.raw()); |
| 3553 } |
| 3554 |
| 3555 |
| 3394 static void PrintMetadata(const char* name, const Object& data) { | 3556 static void PrintMetadata(const char* name, const Object& data) { |
| 3395 if (data.IsError()) { | 3557 if (data.IsError()) { |
| 3396 OS::Print("Error in metadata evaluation for %s: '%s'\n", | 3558 OS::Print("Error in metadata evaluation for %s: '%s'\n", |
| 3397 name, | 3559 name, |
| 3398 Error::Cast(data).ToErrorCString()); | 3560 Error::Cast(data).ToErrorCString()); |
| 3399 } | 3561 } |
| 3400 EXPECT(data.IsArray()); | 3562 EXPECT(data.IsArray()); |
| 3401 const Array& metadata = Array::Cast(data); | 3563 const Array& metadata = Array::Cast(data); |
| 3402 OS::Print("Metadata for %s has %" Pd " values:\n", name, metadata.Length()); | 3564 OS::Print("Metadata for %s has %" Pd " values:\n", name, metadata.Length()); |
| 3403 Object& elem = Object::Handle(); | 3565 Object& elem = Object::Handle(); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3767 // Simple map. | 3929 // Simple map. |
| 3768 // | 3930 // |
| 3769 // TODO(turnidge): Consider showing something like: {1: 2, 2: 'otter'} | 3931 // TODO(turnidge): Consider showing something like: {1: 2, 2: 'otter'} |
| 3770 result = Dart_GetField(lib, NewString("simple_map")); | 3932 result = Dart_GetField(lib, NewString("simple_map")); |
| 3771 EXPECT_VALID(result); | 3933 EXPECT_VALID(result); |
| 3772 obj ^= Api::UnwrapHandle(result); | 3934 obj ^= Api::UnwrapHandle(result); |
| 3773 EXPECT_STREQ("Instance of '_LinkedHashMap'", obj.ToUserCString()); | 3935 EXPECT_STREQ("Instance of '_LinkedHashMap'", obj.ToUserCString()); |
| 3774 } | 3936 } |
| 3775 | 3937 |
| 3776 } // namespace dart | 3938 } // namespace dart |
| OLD | NEW |