Skip to content

Commit

Permalink
fix(core): fix potential NPE when reading default init options from g…
Browse files Browse the repository at this point in the history
…lobal object in dev environment (apache#19217)

* fix: '__ECHARTS__DEFAULT__RENDERER__' of undefined

* fix: Reduce converted code size

* fix: Remove ternary operations
  • Loading branch information
sunpm authored Oct 18, 2023
1 parent 522c75d commit 677adea
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/core/echarts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,20 +412,19 @@ class ECharts extends Eventful<ECEventDefinition> {
let defaultRenderer = 'canvas';
let defaultCoarsePointer: 'auto' | boolean = 'auto';
let defaultUseDirtyRect = false;

if (__DEV__) {
const root = (
/* eslint-disable-next-line */
env.hasGlobalWindow ? window : global
) as any;

defaultRenderer = root.__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;

defaultCoarsePointer = retrieve2(root.__ECHARTS__DEFAULT__COARSE_POINTER, defaultCoarsePointer);
if (root) {
defaultRenderer = retrieve2(root.__ECHARTS__DEFAULT__RENDERER__, defaultRenderer);
defaultCoarsePointer = retrieve2(root.__ECHARTS__DEFAULT__COARSE_POINTER, defaultCoarsePointer);
defaultUseDirtyRect = retrieve2(root.__ECHARTS__DEFAULT__USE_DIRTY_RECT__, defaultUseDirtyRect);
}

const devUseDirtyRect = root.__ECHARTS__DEFAULT__USE_DIRTY_RECT__;
defaultUseDirtyRect = devUseDirtyRect == null
? defaultUseDirtyRect
: devUseDirtyRect;
}

const zr = this._zr = zrender.init(dom, {
Expand Down

0 comments on commit 677adea

Please sign in to comment.