fix: patch Instance::now

This commit is contained in:
2023-01-20 23:27:55 +08:00
parent c997aab841
commit e43846f8c5

View File

@@ -13,7 +13,7 @@ use crate::{
use crate::{JsError, JsNativeError}; use crate::{JsError, JsNativeError};
use boa_interner::ToInternedString; use boa_interner::ToInternedString;
use boa_profiler::Profiler; use boa_profiler::Profiler;
use std::{convert::TryInto, mem::size_of, time::Instant}; use std::{convert::TryInto, mem::size_of};
mod call_frame; mod call_frame;
mod code_block; mod code_block;
@@ -216,13 +216,18 @@ impl Context<'_> {
.code_block .code_block
.instruction_operands(&mut pc, self.interner()); .instruction_operands(&mut pc, self.interner());
let instant = Instant::now(); // wasm32 not supports `Instant::now()`
#[cfg(not(target_arch = "wasm32"))]
let instant = std::time::Instant::now();
let result = self.execute_instruction(); let result = self.execute_instruction();
let duration = instant.elapsed(); #[cfg(target_arch = "wasm32")]
let duration_micros = -1;
#[cfg(not(target_arch = "wasm32"))]
let duration_micros = instant.elapsed().as_micros();
println!( println!(
"{:<TIME_COLUMN_WIDTH$} {:<OPCODE_COLUMN_WIDTH$} {operands:<OPERAND_COLUMN_WIDTH$} {}", "{:<TIME_COLUMN_WIDTH$} {:<OPCODE_COLUMN_WIDTH$} {operands:<OPERAND_COLUMN_WIDTH$} {}",
format!("{}μs", duration.as_micros()), format!("{}μs", duration_micros),
opcode.as_str(), opcode.as_str(),
match self.vm.stack.last() { match self.vm.stack.last() {
Some(value) if value.is_callable() => "[function]".to_string(), Some(value) if value.is_callable() => "[function]".to_string(),