Commit 36ebaf21 authored by machenbach's avatar machenbach Committed by Commit bot

Revert of [inspector] fix timestamp formatting with non C locales (patchset #7...

Revert of [inspector] fix timestamp formatting with non C locales (patchset #7 id:120001 of https://codereview.chromium.org/2410933002/ )

Reason for revert:
Breaks layout tests:
https://build.chromium.org/p/client.v8.fyi/builders/V8-Blink%20Linux%2064/builds/10548

See also:
https://github.com/v8/v8/wiki/Blink-layout-tests

Original issue's description:
> [inspector] fix timestamp formatting with non C locales
>
> If current locale has "," as decimal separator then message for consoleAPICalled will be corrupted.
>
> BUG=chromium:653424
> R=dgozman@chromium.org
>
> Committed: https://crrev.com/dde5ef75cbac1eb7e2dae59b246e4a0d0ba6a0f4
> Cr-Commit-Position: refs/heads/master@{#40190}

TBR=dgozman@chromium.org,kozyatinskiy@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=chromium:653424

Review-Url: https://codereview.chromium.org/2419453002
Cr-Commit-Position: refs/heads/master@{#40200}
parent 5c9d0ac9
...@@ -8,10 +8,8 @@ ...@@ -8,10 +8,8 @@
#include <cctype> #include <cctype>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <iomanip>
#include <limits> #include <limits>
#include <locale> #include <locale>
#include <sstream>
#include <string> #include <string>
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
...@@ -383,19 +381,26 @@ String16 String16::fromInteger(size_t number) { ...@@ -383,19 +381,26 @@ String16 String16::fromInteger(size_t number) {
// static // static
String16 String16::fromDouble(double number) { String16 String16::fromDouble(double number) {
std::ostringstream s; const size_t kBufferSize = 100;
s.imbue(std::locale("C")); char buffer[kBufferSize];
s << std::fixed << std::setprecision(std::numeric_limits<double>::digits10) v8::base::OS::SNPrintF(buffer, kBufferSize, "%f", number);
<< number; return String16(buffer);
return String16(s.str().c_str());
} }
// static // static
String16 String16::fromDouble(double number, int precision) { String16 String16::fromDoublePrecision3(double number) {
std::ostringstream s; const size_t kBufferSize = 100;
s.imbue(std::locale("C")); char buffer[kBufferSize];
s << std::fixed << std::setprecision(precision) << number; v8::base::OS::SNPrintF(buffer, kBufferSize, "%.3g", number);
return String16(s.str().c_str()); return String16(buffer);
}
// static
String16 String16::fromDoublePrecision6(double number) {
const size_t kBufferSize = 100;
char buffer[kBufferSize];
v8::base::OS::SNPrintF(buffer, kBufferSize, "%.6g", number);
return String16(buffer);
} }
int String16::toInteger(bool* ok) const { int String16::toInteger(bool* ok) const {
......
...@@ -35,7 +35,8 @@ class String16 { ...@@ -35,7 +35,8 @@ class String16 {
static String16 fromInteger(int); static String16 fromInteger(int);
static String16 fromInteger(size_t); static String16 fromInteger(size_t);
static String16 fromDouble(double); static String16 fromDouble(double);
static String16 fromDouble(double, int precision); static String16 fromDoublePrecision3(double);
static String16 fromDoublePrecision6(double);
int toInteger(bool* ok = nullptr) const; int toInteger(bool* ok = nullptr) const;
String16 stripWhiteSpace() const; String16 stripWhiteSpace() const;
......
...@@ -93,8 +93,8 @@ class V8ValueStringBuilder { ...@@ -93,8 +93,8 @@ class V8ValueStringBuilder {
if (value->IsSymbolObject()) if (value->IsSymbolObject())
return append(v8::Local<v8::SymbolObject>::Cast(value)->ValueOf()); return append(v8::Local<v8::SymbolObject>::Cast(value)->ValueOf());
if (value->IsNumberObject()) { if (value->IsNumberObject()) {
m_builder.append(String16::fromDouble( m_builder.append(String16::fromDoublePrecision6(
v8::Local<v8::NumberObject>::Cast(value)->ValueOf(), 6)); v8::Local<v8::NumberObject>::Cast(value)->ValueOf()));
return true; return true;
} }
if (value->IsBooleanObject()) { if (value->IsBooleanObject()) {
......
...@@ -431,7 +431,7 @@ static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info, ...@@ -431,7 +431,7 @@ static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
double elapsed = client->currentTimeMS() - double elapsed = client->currentTimeMS() -
helper.getDoubleFromMap(timeMap, protocolTitle, 0.0); helper.getDoubleFromMap(timeMap, protocolTitle, 0.0);
String16 message = String16 message =
protocolTitle + ": " + String16::fromDouble(elapsed, 3) + "ms"; protocolTitle + ": " + String16::fromDoublePrecision3(elapsed) + "ms";
helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
} }
} }
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
#include <unistd.h> // NOLINT #include <unistd.h> // NOLINT
#endif // !defined(_WIN32) && !defined(_WIN64) #endif // !defined(_WIN32) && !defined(_WIN64)
#include <locale.h>
#include "include/libplatform/libplatform.h" #include "include/libplatform/libplatform.h"
#include "include/v8.h" #include "include/v8.h"
...@@ -31,9 +29,7 @@ class UtilsExtension : public v8::Extension { ...@@ -31,9 +29,7 @@ class UtilsExtension : public v8::Extension {
public: public:
UtilsExtension() UtilsExtension()
: v8::Extension("v8_inspector/utils", : v8::Extension("v8_inspector/utils",
"native function print();" "native function print(); native function quit();") {}
"native function quit();"
"native function setlocale();") {}
virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name) { v8::Isolate* isolate, v8::Local<v8::String> name) {
v8::Local<v8::Context> context = isolate->GetCurrentContext(); v8::Local<v8::Context> context = isolate->GetCurrentContext();
...@@ -48,12 +44,6 @@ class UtilsExtension : public v8::Extension { ...@@ -48,12 +44,6 @@ class UtilsExtension : public v8::Extension {
.ToLocalChecked()) .ToLocalChecked())
.FromJust()) { .FromJust()) {
return v8::FunctionTemplate::New(isolate, UtilsExtension::Quit); return v8::FunctionTemplate::New(isolate, UtilsExtension::Quit);
} else if (name->Equals(context,
v8::String::NewFromUtf8(isolate, "setlocale",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
return v8::FunctionTemplate::New(isolate, UtilsExtension::SetLocale);
} }
return v8::Local<v8::FunctionTemplate>(); return v8::Local<v8::FunctionTemplate>();
} }
...@@ -93,15 +83,6 @@ class UtilsExtension : public v8::Extension { ...@@ -93,15 +83,6 @@ class UtilsExtension : public v8::Extension {
} }
static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) { Exit(); } static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) { Exit(); }
static void SetLocale(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1 || !args[0]->IsString()) {
fprintf(stderr, "Internal error: setlocale get one string argument.");
Exit();
}
v8::String::Utf8Value str(args[0]);
setlocale(LC_NUMERIC, *str);
}
}; };
class SetTimeoutTask : public TaskRunner::Task { class SetTimeoutTask : public TaskRunner::Task {
......
Running test: consoleLogWithDefaultLocale
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
description : 239
type : number
value : 239
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 8
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
}
]
}
timestamp : <timestamp>
type : log
}
}
Running test: consoleTimeWithCommaAsSeparator
set locale to fr_CA.UTF-8 (has comma as separator)
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
type : string
value : a: x.xms
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 27
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
}
]
}
timestamp : <timestamp>
type : debug
}
}
Running test: consoleLogWithCommaAsSeparator
set locale to fr_CA.UTF-8 (has comma as separator)
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
description : 239
type : number
value : 239
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 8
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
}
]
}
timestamp : <timestamp>
type : log
}
}
Running test: consoleTimeWithCommaAfterConsoleLog
set locale to fr_CA.UTF-8 (has comma as separator)
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
description : 239
type : number
value : 239
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 8
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
}
]
}
timestamp : <timestamp>
type : log
}
}
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
type : string
value : a: x.xms
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 27
functionName :
lineNumber : 0
scriptId : <scriptId>
url :
}
]
}
timestamp : <timestamp>
type : debug
}
}
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Protocol.Runtime.enable();
Protocol.Runtime.onConsoleAPICalled(dumpConsoleApiCalled);
InspectorTest.runTestSuite([
function consoleLogWithDefaultLocale(next) {
Protocol.Runtime.evaluate({ expression: "console.log(239) "}).then(next);
},
function consoleTimeWithCommaAsSeparator(next) {
InspectorTest.log("set locale to fr_CA.UTF-8 (has comma as separator)");
setlocale("fr_CA.UTF-8");
Protocol.Runtime.evaluate({ expression: "console.time(\"a\"); console.timeEnd(\"a\")"}).then(next);
},
function consoleLogWithCommaAsSeparator(next) {
InspectorTest.log("set locale to fr_CA.UTF-8 (has comma as separator)");
setlocale("fr_CA.UTF-8");
Protocol.Runtime.evaluate({ expression: "console.log(239) "}).then(next);
},
function consoleTimeWithCommaAfterConsoleLog(next) {
InspectorTest.log("set locale to fr_CA.UTF-8 (has comma as separator)");
setlocale("fr_CA.UTF-8");
Protocol.Runtime.evaluate({ expression: "console.log(239) "})
.then(() => Protocol.Runtime.evaluate({ expression: "console.time(\"a\"); console.timeEnd(\"a\")"}))
.then(next);
}
]);
function dumpConsoleApiCalled(message) {
var firstArg = message.params.args[0];
if (firstArg.type === "string")
firstArg.value = firstArg.value.replace(/[0-9]+/g, "x");
InspectorTest.logMessage(message);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment