MCPcopy Create free account
hub / github.com/Tracktion/choc / v8ToChoc

Method v8ToChoc

choc/javascript/choc_javascript_V8.h:302–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300 }
301
302 choc::value::Value v8ToChoc (v8::Local<v8::Context> c, const v8::Local<v8::Value>& value)
303 {
304 if (value->IsProxy())
305 return v8ToChoc (c, v8::Local<v8::Proxy>::Cast (value)->GetTarget());
306
307 if (value->IsString()) return choc::value::createString (v8StringToStd (value));
308 if (value->IsInt32()) return choc::value::createInt32 (value->Int32Value (c).ToChecked());
309 if (value->IsBoolean()) return choc::value::createBool (value->BooleanValue (isolate));
310 if (value->IsNumber()) return choc::value::createFloat64 (value->NumberValue (c).ToChecked());
311 if (value->IsBigInt()) return choc::value::createInt64 (value->ToBigInt (c).ToLocalChecked()->Int64Value());
312
313 if (value->IsArray())
314 {
315 auto a = v8::Local<v8::Array>::Cast (value);
316 auto len = a->Length();
317
318 return choc::value::createArray (len, [&] (uint32_t index)
319 {
320 auto item = a->Get (c, index);
321
322 if (item.IsEmpty())
323 return choc::value::Value();
324
325 return v8ToChoc (c, item.ToLocalChecked());
326 });
327 }
328
329 if (value->IsArrayBuffer() || value->IsArrayBufferView())
330 {
331 auto a = v8::Local<v8::TypedArray>::Cast (value);
332 auto len = static_cast<uint32_t> (a->Length());
333
334 return choc::value::createArray (len, [&] (uint32_t index)
335 {
336 auto item = a->Get (c, index);
337
338 if (item.IsEmpty())
339 return choc::value::Value();
340
341 return v8ToChoc (c, item.ToLocalChecked());
342 });
343 }
344
345 if (value->IsObject())
346 {
347 auto o = value->ToObject (c).ToLocalChecked();
348 auto propNames = o->GetPropertyNames (c);
349 std::string className;
350
351 if (propNames.IsEmpty())
352 return {};
353
354 std::vector<std::string> propKeys;
355 std::vector<v8::Local<v8::Value>> propValues;
356
357 {
358 auto iterator = [&] (v8::Local<v8::Value> key)
359 {

Callers

nothing calls this directly

Calls 13

createInt32Function · 0.85
createBoolFunction · 0.85
createFloat64Function · 0.85
createInt64Function · 0.85
createArrayFunction · 0.85
ValueClass · 0.85
createObjectFunction · 0.85
emplace_backMethod · 0.80
setMemberMethod · 0.80
createStringFunction · 0.50
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected