| 7711 | |
| 7712 | |
| 7713 | ResultType Script::PreparseCatchClass(Line *aLine) |
| 7714 | { |
| 7715 | if (!aLine->mArgc || !aLine->mArg->length) // PreparseCatchVar() may have already set length to exclude " as output_var". |
| 7716 | return OK; |
| 7717 | IObject *prototype[MAX_ARGS - 1]; // Set an arbitrary limit to simplify the code; using MAX_ARGS to keep things consistent, -1 for the output var. |
| 7718 | int prototype_count = 0; |
| 7719 | for (LPTSTR cp = aLine->mArg->text, cp_end = cp + aLine->mArg->length; cp < cp_end; ) |
| 7720 | { |
| 7721 | if (prototype_count) |
| 7722 | { |
| 7723 | if (*cp != g_delimiter) |
| 7724 | return aLine->LineError(ERR_EXPR_SYNTAX); |
| 7725 | if (prototype_count == _countof(prototype)) |
| 7726 | return aLine->LineError(_T("Too many classes.")); |
| 7727 | cp = omit_leading_whitespace(cp + 1); |
| 7728 | } |
| 7729 | LPTSTR end = cp; |
| 7730 | while (IS_IDENTIFIER_CHAR(*end) || *end == '.') ++end; |
| 7731 | LPTSTR next = omit_leading_whitespace(end); |
| 7732 | if (end == cp) |
| 7733 | return aLine->LineError(ERR_EXPR_SYNTAX); |
| 7734 | auto cls = FindClass(cp, end - cp); |
| 7735 | if ( !cls || !(prototype[prototype_count++] = cls->GetOwnPropObj(_T("Prototype"))) ) |
| 7736 | return aLine->LineError(_T("Invalid class."), FAIL, cp); |
| 7737 | cp = next; |
| 7738 | } |
| 7739 | if (prototype_count) // Currently should always be non-zero due to the length check. |
| 7740 | { |
| 7741 | auto args = (CatchStatementArgs *)aLine->mAttribute; |
| 7742 | args->prototype = SimpleHeap::Alloc<IObject *>(prototype_count); |
| 7743 | args->prototype_count = prototype_count; |
| 7744 | memcpy(args->prototype, prototype, prototype_count * sizeof(IObject *)); |
| 7745 | } |
| 7746 | return OK; |
| 7747 | } |
| 7748 | |
| 7749 | |
| 7750 |
nothing calls this directly
no test coverage detected