Skip to content

Commit f2a3a40

Browse files
authored
fix(runtime): append null check to object check (#1684)
1 parent 849a221 commit f2a3a40

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

runtimes/nodejs/src/handler/invoke.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
FunctionDebugExecutor,
1313
} from '../support/engine'
1414
import pako from 'pako'
15-
import { base64ToUint8Array, uint8ArrayToBase64 } from '../support/utils'
15+
import { base64ToUint8Array, isObject, uint8ArrayToBase64 } from '../support/utils'
1616

1717
export async function handleInvokeFunction(req: IRequest, res: Response) {
1818
const name = req.params?.name
@@ -90,7 +90,7 @@ async function invokeFunction(
9090

9191
// reject request if interceptor return false
9292
if (
93-
typeof result.data === 'object' &&
93+
isObject(result.data) &&
9494
result.data.__type__ === '__interceptor__' &&
9595
result.data.__res__ == false
9696
) {
@@ -200,7 +200,7 @@ async function invokeDebug(
200200

201201
// reject request if interceptor return false
202202
if (
203-
typeof result.data === 'object' &&
203+
isObject(result.data) &&
204204
result.data.__type__ === '__interceptor__' &&
205205
result.data.__res__ == false
206206
) {

runtimes/nodejs/src/support/engine/console.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as util from 'util'
22
import chalk from 'chalk'
33
import { padStart } from 'lodash'
44
import Config from '../../config'
5+
import { isObject } from '../utils'
56

67
enum LogLevel {
78
DEBUG = 'DEBUG',
@@ -31,7 +32,7 @@ export class Console {
3132
let content = params
3233
.map((param) => {
3334
if (typeof param === 'string') return this._colorize(level, param)
34-
if (typeof param === 'object') {
35+
if (isObject(param)) {
3536
return this._colorize(
3637
level,
3738
util.inspect(param, { depth: Config.LOG_DEPTH, colors: true }),

runtimes/nodejs/src/support/utils.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function deepFreeze(object: Object) {
6868
for (const name of propNames) {
6969
const value = object[name]
7070

71-
if (value && typeof value === 'object') {
71+
if (isObject(value)) {
7272
deepFreeze(value)
7373
}
7474
}
@@ -114,4 +114,13 @@ export function uint8ArrayToBase64(buffer: Uint8Array) {
114114
export function base64ToUint8Array(base64: string) {
115115
const buffer = Buffer.from(base64, 'base64')
116116
return new Uint8Array(buffer)
117-
}
117+
}
118+
119+
/**
120+
* is object.
121+
* @param obj
122+
* @returns
123+
*/
124+
export function isObject(obj: unknown): obj is Object {
125+
return obj !== null && typeof obj === 'object'
126+
}

0 commit comments

Comments
 (0)