MCPcopy Create free account
hub / github.com/Snapchat/Valdi / valueToLong

Method valueToLong

valdi/src/valdi/runtime/Interfaces/IJavaScriptContext.cpp:259–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257 if (_longConstructor.empty()) {
258 exceptionTracker.onError(Error("Long Constructor is not configured"));
259 return JSValueRef();
260 }
261
262 std::initializer_list<JSValueRef> parameters = {
263 newNumber(value.lowBits()), newNumber(value.highBits()), newBool(value.isUnsigned())};
264
265 JSFunctionCallContext params(*this, parameters.begin(), parameters.size(), exceptionTracker);
266
267 return callObjectAsConstructor(_longConstructor.get(), params);
268}
269
270JSValueRef IJavaScriptContext::newArrayBufferCopy(const Byte* data, size_t size, JSExceptionTracker& exceptionTracker) {
271 return newArrayBuffer(makeShared<ByteBuffer>(data, data + size)->toBytesView(), exceptionTracker);
272}
273
274JavaScriptLong IJavaScriptContext::valueToLong(const JSValue& value, JSExceptionTracker& exceptionTracker) {
275 static auto kLow = STRING_LITERAL("low");
276 static auto kHigh = STRING_LITERAL("high");
277 static auto kUnsigned = STRING_LITERAL("unsigned");
278
279 auto low = getObjectProperty(value, getPropertyNameCached(kLow), exceptionTracker);
280 if (!exceptionTracker) {
281 return JavaScriptLong();
282 }
283
284 auto high = getObjectProperty(value, getPropertyNameCached(kHigh), exceptionTracker);
285 if (!exceptionTracker) {
286 return JavaScriptLong();
287 }
288
289 auto isUnsigned = getObjectProperty(value, getPropertyNameCached(kUnsigned), exceptionTracker);
290 if (!exceptionTracker) {
291 return JavaScriptLong();
292 }
293
294 auto lowValue = valueToInt(low.get(), exceptionTracker);
295 if (!exceptionTracker) {
296 return JavaScriptLong();
297 }
298

Callers

nothing calls this directly

Calls 2

JavaScriptLongClass · 0.70
getMethod · 0.65

Tested by

no test coverage detected