| Index: runtime/lib/mirrors.cc
|
| diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc
|
| index ed78b7bbfe150d5073e390c1a46cc88800bbbff1..bafb2ea95300c64a00bdd97ba885710a302e289a 100644
|
| --- a/runtime/lib/mirrors.cc
|
| +++ b/runtime/lib/mirrors.cc
|
| @@ -1292,6 +1292,35 @@ DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) {
|
| }
|
|
|
|
|
| +DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) {
|
| + GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
|
| + const Function& func = Function::Handle(ref.GetFunctionReferent());
|
| + const Script& script = Script::Handle(func.script());
|
| + const TokenStream& stream = TokenStream::Handle(script.tokens());
|
| + const TokenStream::Iterator tkit(stream, func.end_token_pos());
|
| + intptr_t from_line;
|
| + intptr_t from_col;
|
| + intptr_t to_line;
|
| + intptr_t to_col;
|
| + script.GetTokenLocation(func.token_pos(), &from_line, &from_col);
|
| + script.GetTokenLocation(func.end_token_pos(), &to_line, &to_col);
|
| + intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length();
|
| + // Handle special cases for end tokens of closures (where we exclude the last
|
| + // token):
|
| + // (1) "foo(() => null, bar);": End token is `,', but we don't print it.
|
| + // (2) "foo(() => null);": End token is ')`, but we don't print it.
|
| + // (3) "var foo = () => null;": End token is `;', but in this case the token
|
| + // semicolon belongs to the assignment so we skip it.
|
| + if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1.
|
| + (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2.
|
| + (tkit.CurrentTokenKind() == Token::kSEMICOLON &&
|
| + String::Handle(func.name()).Equals("<anonymous closure>"))) { // Case 3.
|
| + last_tok_len = 0;
|
| + }
|
| + return script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len);
|
| +}
|
| +
|
| +
|
| DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) {
|
| GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
|
| const Class& cls = Class::Handle(ref.GetClassReferent());
|
|
|