From 0fcec043825112942e0022020ae377a78a294109 Mon Sep 17 00:00:00 2001 From: Mattias Gaertner Date: Thu, 17 May 2018 08:35:27 +0000 Subject: [PATCH] pastojs: fixed removing leading zeroes from hex numbers git-svn-id: trunk@39010 - --- packages/pastojs/src/fppas2js.pp | 35 +++++++++++++++++++++------- packages/pastojs/tests/tcmodules.pas | 4 +++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp index d9e97f6da0..36b6d29d01 100644 --- a/packages/pastojs/src/fppas2js.pp +++ b/packages/pastojs/src/fppas2js.pp @@ -6277,19 +6277,35 @@ function TPasToJSConverter.ConvertPrimitiveExpression(El: TPrimitiveExpr; function DeleteLeadingZeroes(const s: string): string; // Note: 01 is in JS octal, and in strict mode forbidden + // $00ff00 -> $ff00 + // 00E001 -> 0E1 + // 0.001 -> 0.001 + // 0.00E1 -> 0.00E1 var i: Integer; begin Result:=s; i:=1; - while i can not be a float, 'E' is a hexdigit + while i we lost precision DoError(20161024230812,nInvalidNumber,sInvalidNumber,[El.Value],El); L:=CreateLiteralNumber(El,Number); - S:=DeleteLeadingZeroes(copy(El.Value,2,length(El.Value))); + S:=DeleteLeadingZeroes(El.Value); + S:=copy(S,2,length(S)); case El.Value[1] of '$': S:='0x'+S; '&': if TargetProcessor=ProcessorECMAScript5 then diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas index c4cfe176ce..1092f168e3 100644 --- a/packages/pastojs/tests/tcmodules.pas +++ b/packages/pastojs/tests/tcmodules.pas @@ -2154,6 +2154,7 @@ begin Add(' i8: byte = 00;'); Add(' u8: nativeuint = $fffffffffffff;'); Add(' u9: nativeuint = $0000000000000;'); + Add(' u10: nativeuint = $00ff00;'); Add('begin'); ConvertProgram; CheckSource('TestVarBaseTypes', @@ -2175,7 +2176,8 @@ begin 'this.i7 =-0x10000000000000;', 'this.i8 = 0;', 'this.u8 = 0xfffffffffffff;', - 'this.u9 = 0x0;' + 'this.u9 = 0x0;', + 'this.u10 = 0xff00;' ]), ''); end;