File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -326,9 +326,11 @@ function initCalculator() {
326326
327327 function safeEval ( expr ) {
328328 try {
329- const cleaned = sanitize ( expr ) ;
330- if ( ! cleaned ) return "" ;
331- return String ( evaluateExpression ( normalize ( cleaned ) ) ) ;
329+ if ( ! expr ) return "" ;
330+ let result = Function ( '"use strict"; return (' + format ( expr ) + ')' ) ( ) ;
331+ if ( result === undefined ) return "" ;
332+ if ( isNaN ( result ) ) return "Error" ;
333+ return String ( result ) ;
332334 } catch {
333335 return "Error" ;
334336 }
@@ -457,21 +459,11 @@ function initCalculator() {
457459 }
458460 }
459461
460- function evaluateCurrent ( ) {
461- const evaluated = safeEval ( expression ) ;
462- expression = evaluated || "" ;
463- update ( ) ;
464- }
465-
466- function deleteLast ( ) {
467- clearIfError ( ) ;
468- expression = expression . slice ( 0 , - 1 ) ;
469- update ( ) ;
470- }
471-
472- function clearExpression ( ) {
473- expression = "" ;
474- update ( ) ;
462+
463+ function clearIfFinished ( ) {
464+ if ( expression === "Error" || expression === "NaN" || expression === "Infinity" || expression === "-Infinity" ) {
465+ expression = "" ;
466+ }
475467 }
476468
477469 document . querySelectorAll ( ".calc-btn" ) . forEach ( btn => {
You can’t perform that action at this time.
0 commit comments