Chromium Code Reviews| Index: runtime/lib/mirrors.cc |
| diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc |
| index 7ab68b6a0c650a8e397e785e62f31e4daa7eccca..b7b3b7ccac9ede5d9235dae5f15285e55d8e58da 100644 |
| --- a/runtime/lib/mirrors.cc |
| +++ b/runtime/lib/mirrors.cc |
| @@ -1277,6 +1277,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 we are in |
|
siva
2013/08/21 22:21:05
In your comment you mention end token is ';' but I
Michael Lippautz (Google)
2013/08/21 23:19:20
Done.
|
| + // an assignment, and we don't want it printed. |
| + if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // (1) |
|
siva
2013/08/21 22:21:05
what does "(1)" mean?
Michael Lippautz (Google)
2013/08/21 23:19:20
I tried to refer to the comment above in the if st
siva
2013/08/26 02:31:28
Maybe replace with "foo() => null, bar);" case
On
|
| + (tkit.CurrentTokenKind() == Token::kRPAREN) || |
| + (tkit.CurrentTokenKind() == Token::kSEMICOLON && |
| + String::Handle(func.name()).Equals("<anonymous closure>"))) { |
| + 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()); |