Changeset 209283 in webkit for trunk/Source/JavaScriptCore/jsc.cpp
- Timestamp:
- Dec 2, 2016, 4:35:25 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/jsc.cpp
r209275 r209283 2511 2511 static JSValue box(ExecState* exec, VM& vm, JSValue wasmValue) 2512 2512 { 2513 2514 2513 JSString* type = jsCast<JSString*>(wasmValue.get(exec, makeIdentifier(vm, "type"))); 2515 2514 JSValue value = wasmValue.get(exec, makeIdentifier(vm, "value")); 2516 2517 auto unboxString = [&] (const char* hexFormat, const char* decFormat, auto& result) {2518 if (!value.isString())2519 return false;2520 2521 const char* str = toCString(jsCast<JSString*>(value)->value(exec)).data();2522 int scanResult;2523 int length = std::strlen(str);2524 if ((length > 2 && (str[0] == '0' && str[1] == 'x'))2525 || (length > 3 && (str[0] == '-' && str[1] == '0' && str[2] == 'x')))2526 #if COMPILER(CLANG)2527 #pragma clang diagnostic push2528 #pragma clang diagnostic ignored "-Wformat-nonliteral"2529 #endif2530 scanResult = sscanf(str, hexFormat, &result);2531 else2532 scanResult = sscanf(str, decFormat, &result);2533 #if COMPILER(CLANG)2534 #pragma clang diagnostic pop2535 #endif2536 RELEASE_ASSERT(scanResult != EOF);2537 return true;2538 };2539 2515 2540 2516 const String& typeString = type->value(exec); 2541 2517 if (typeString == "i64") { 2542 2518 int64_t result; 2543 if (!unboxString("%llx", "%lld", result)) 2544 CRASH(); 2519 const char* str = toCString(jsCast<JSString*>(value)->value(exec)).data(); 2520 int scanResult; 2521 if (std::strlen(str) > 2 && str[0] == '0' && str[1] == 'x') 2522 scanResult = sscanf(str, "%llx", &result); 2523 else 2524 scanResult = sscanf(str, "%lld", &result); 2525 RELEASE_ASSERT(scanResult != EOF); 2545 2526 return JSValue::decode(result); 2546 2527 } 2528 RELEASE_ASSERT(value.isNumber()); 2547 2529 2548 2530 if (typeString == "i32") { 2549 int32_t result; 2550 if (!unboxString("%x", "%d", result)) 2551 result = value.asInt32(); 2552 return JSValue::decode(static_cast<uint32_t>(result)); 2553 } 2554 2555 if (typeString == "f32") { 2556 float result; 2557 if (!unboxString("%a", "%f", result)) 2558 result = value.toFloat(exec); 2559 return JSValue::decode(bitwise_cast<uint32_t>(result)); 2560 } 2531 RELEASE_ASSERT(value.isInt32()); 2532 return JSValue::decode(static_cast<uint32_t>(value.asInt32())); 2533 } 2534 2535 if (typeString == "f32") 2536 return JSValue::decode(bitwise_cast<uint32_t>(value.toFloat(exec))); 2561 2537 2562 2538 RELEASE_ASSERT(typeString == "f64"); 2563 double result; 2564 if (!unboxString("%la", "%lf", result)) 2565 result = value.asNumber(); 2566 return JSValue::decode(bitwise_cast<uint64_t>(result)); 2539 return JSValue::decode(bitwise_cast<uint64_t>(value.asNumber())); 2567 2540 } 2568 2541
Note:
See TracChangeset
for help on using the changeset viewer.