Fix conversion from double to int16_t in JSC bindings

Summary:
Converting from double to int16_t is undefined behavior if the value
doesn't fit in int16_t.

Reviewed By: tmikov

Differential Revision: D8925246

fbshipit-source-id: 4cf57631686a4ce05546f8d30a46e3f9def3aee2
This commit is contained in:
Simon Jensen 2018-07-24 11:52:49 -07:00 committed by Facebook Github Bot
parent 8116c3f91a
commit 17485e8ed4
1 changed files with 4 additions and 2 deletions

View File

@ -177,7 +177,8 @@ static JSValueRef nativeQPLMarkerEnd(
if (isReady() && grabDoubles(4, targets, ctx, argumentCount, arguments, exception)) {
int32_t markerId = (int32_t) targets[0];
int32_t instanceKey = (int32_t) targets[1];
int16_t actionId = (int16_t) targets[2];
// NOTE: avoid undefined behavior when the value does not find in int16_t.
int16_t actionId = (int16_t) (int32_t) targets[2];
int64_t timestamp = (int64_t) targets[3];
JQuickPerformanceLoggerProvider::get()->markerEnd(markerId, instanceKey, actionId, timestamp);
}
@ -230,7 +231,8 @@ static JSValueRef nativeQPLMarkerNote(
if (isReady() && grabDoubles(4, targets, ctx, argumentCount, arguments, exception)) {
int32_t markerId = (int32_t) targets[0];
int32_t instanceKey = (int32_t) targets[1];
int16_t actionId = (int16_t) targets[2];
// NOTE: avoid undefined behavior when the value does not find in int16_t.
int16_t actionId = (int16_t) (int32_t) targets[2];
int64_t timestamp = (int64_t) targets[3];
JQuickPerformanceLoggerProvider::get()->markerNote(markerId, instanceKey, actionId, timestamp);
}