diff options
author | 2021-10-25 20:34:20 +0200 | |
---|---|---|
committer | 2021-10-31 19:26:12 +0100 | |
commit | dc00bb67a9ef7861427f2d5eb86745f5775d1863 (patch) | |
tree | 01e7eea411e538f83cb339173428e769b63cfdf9 /language-web/src/main/js/editor | |
parent | feat(web): application-level pings (diff) | |
download | refinery-dc00bb67a9ef7861427f2d5eb86745f5775d1863.tar.gz refinery-dc00bb67a9ef7861427f2d5eb86745f5775d1863.tar.zst refinery-dc00bb67a9ef7861427f2d5eb86745f5775d1863.zip |
fix(web): only try to read properties of objects
Diffstat (limited to 'language-web/src/main/js/editor')
-rw-r--r-- | language-web/src/main/js/editor/xtextMessages.ts | 9 | ||||
-rw-r--r-- | language-web/src/main/js/editor/xtextServiceResults.ts | 12 |
2 files changed, 14 insertions, 7 deletions
diff --git a/language-web/src/main/js/editor/xtextMessages.ts b/language-web/src/main/js/editor/xtextMessages.ts index d3cb9425..be3125e6 100644 --- a/language-web/src/main/js/editor/xtextMessages.ts +++ b/language-web/src/main/js/editor/xtextMessages.ts | |||
@@ -12,7 +12,8 @@ export interface IXtextWebOkResponse { | |||
12 | 12 | ||
13 | export function isOkResponse(response: unknown): response is IXtextWebOkResponse { | 13 | export function isOkResponse(response: unknown): response is IXtextWebOkResponse { |
14 | const okResponse = response as IXtextWebOkResponse; | 14 | const okResponse = response as IXtextWebOkResponse; |
15 | return typeof okResponse.id === 'string' | 15 | return typeof okResponse === 'object' |
16 | && typeof okResponse.id === 'string' | ||
16 | && typeof okResponse.response !== 'undefined'; | 17 | && typeof okResponse.response !== 'undefined'; |
17 | } | 18 | } |
18 | 19 | ||
@@ -30,7 +31,8 @@ export interface IXtextWebErrorResponse { | |||
30 | 31 | ||
31 | export function isErrorResponse(response: unknown): response is IXtextWebErrorResponse { | 32 | export function isErrorResponse(response: unknown): response is IXtextWebErrorResponse { |
32 | const errorResponse = response as IXtextWebErrorResponse; | 33 | const errorResponse = response as IXtextWebErrorResponse; |
33 | return typeof errorResponse.id === 'string' | 34 | return typeof errorResponse === 'object' |
35 | && typeof errorResponse.id === 'string' | ||
34 | && typeof errorResponse.error === 'string' | 36 | && typeof errorResponse.error === 'string' |
35 | && VALID_XTEXT_WEB_ERROR_KINDS.includes(errorResponse.error) | 37 | && VALID_XTEXT_WEB_ERROR_KINDS.includes(errorResponse.error) |
36 | && typeof errorResponse.message === 'string'; | 38 | && typeof errorResponse.message === 'string'; |
@@ -48,7 +50,8 @@ export interface IXtextWebPushMessage { | |||
48 | 50 | ||
49 | export function isPushMessage(response: unknown): response is IXtextWebPushMessage { | 51 | export function isPushMessage(response: unknown): response is IXtextWebPushMessage { |
50 | const pushMessage = response as IXtextWebPushMessage; | 52 | const pushMessage = response as IXtextWebPushMessage; |
51 | return typeof pushMessage.resource === 'string' | 53 | return typeof pushMessage === 'object' |
54 | && typeof pushMessage.resource === 'string' | ||
52 | && typeof pushMessage.stateId === 'string' | 55 | && typeof pushMessage.stateId === 'string' |
53 | && typeof pushMessage.service === 'string' | 56 | && typeof pushMessage.service === 'string' |
54 | && typeof pushMessage.push !== 'undefined'; | 57 | && typeof pushMessage.push !== 'undefined'; |
diff --git a/language-web/src/main/js/editor/xtextServiceResults.ts b/language-web/src/main/js/editor/xtextServiceResults.ts index 8fa7a321..8a4afa40 100644 --- a/language-web/src/main/js/editor/xtextServiceResults.ts +++ b/language-web/src/main/js/editor/xtextServiceResults.ts | |||
@@ -4,7 +4,8 @@ export interface IPongResult { | |||
4 | 4 | ||
5 | export function isPongResult(result: unknown): result is IPongResult { | 5 | export function isPongResult(result: unknown): result is IPongResult { |
6 | const pongResult = result as IPongResult; | 6 | const pongResult = result as IPongResult; |
7 | return typeof pongResult.pong === 'string'; | 7 | return typeof pongResult === 'object' |
8 | && typeof pongResult.pong === 'string'; | ||
8 | } | 9 | } |
9 | 10 | ||
10 | export interface IDocumentStateResult { | 11 | export interface IDocumentStateResult { |
@@ -13,7 +14,8 @@ export interface IDocumentStateResult { | |||
13 | 14 | ||
14 | export function isDocumentStateResult(result: unknown): result is IDocumentStateResult { | 15 | export function isDocumentStateResult(result: unknown): result is IDocumentStateResult { |
15 | const documentStateResult = result as IDocumentStateResult; | 16 | const documentStateResult = result as IDocumentStateResult; |
16 | return typeof documentStateResult.stateId === 'string'; | 17 | return typeof documentStateResult === 'object' |
18 | && typeof documentStateResult.stateId === 'string'; | ||
17 | } | 19 | } |
18 | 20 | ||
19 | export const VALID_CONFLICTS = ['invalidStateId', 'canceled'] as const; | 21 | export const VALID_CONFLICTS = ['invalidStateId', 'canceled'] as const; |
@@ -50,7 +52,8 @@ export interface IIssue { | |||
50 | 52 | ||
51 | export function isIssue(value: unknown): value is IIssue { | 53 | export function isIssue(value: unknown): value is IIssue { |
52 | const issue = value as IIssue; | 54 | const issue = value as IIssue; |
53 | return typeof issue.description === 'string' | 55 | return typeof issue === 'object' |
56 | && typeof issue.description === 'string' | ||
54 | && typeof issue.severity === 'string' | 57 | && typeof issue.severity === 'string' |
55 | && VALID_SEVERITIES.includes(issue.severity) | 58 | && VALID_SEVERITIES.includes(issue.severity) |
56 | && typeof issue.line === 'number' | 59 | && typeof issue.line === 'number' |
@@ -65,6 +68,7 @@ export interface IValidationResult { | |||
65 | 68 | ||
66 | export function isValidationResult(result: unknown): result is IValidationResult { | 69 | export function isValidationResult(result: unknown): result is IValidationResult { |
67 | const validationResult = result as IValidationResult; | 70 | const validationResult = result as IValidationResult; |
68 | return Array.isArray(validationResult.issues) | 71 | return typeof validationResult === 'object' |
72 | && Array.isArray(validationResult.issues) | ||
69 | && validationResult.issues.every(isIssue); | 73 | && validationResult.issues.every(isIssue); |
70 | } | 74 | } |