Index: src/runtime.cc |
diff --git a/src/runtime.cc b/src/runtime.cc |
index c11a00528d02e37bce4826d5cf180bf85c795b78..f546629df55af36ad15b22409ecaeef0b83075d9 100644 |
--- a/src/runtime.cc |
+++ b/src/runtime.cc |
@@ -7848,6 +7848,35 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) { |
} |
+RUNTIME_FUNCTION(MaybeObject*, Runtime_PopulateTrigonometricTable) { |
+ HandleScope scope(isolate); |
+ ASSERT(args.length() == 3); |
+ CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, sin_table, 0); |
+ CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, cos_table, 1); |
+ CONVERT_SMI_ARG_CHECKED(samples, 2); |
+ RUNTIME_ASSERT(sin_table->type() == kExternalDoubleArray); |
+ RUNTIME_ASSERT(cos_table->type() == kExternalDoubleArray); |
+ double* sin_buffer = reinterpret_cast<double*>( |
+ JSArrayBuffer::cast(sin_table->buffer())->backing_store()); |
+ double* cos_buffer = reinterpret_cast<double*>( |
+ JSArrayBuffer::cast(cos_table->buffer())->backing_store()); |
+ |
+ static const double pi_half = 3.1415926535897932 / 2; |
+ double interval = pi_half / samples; |
+ for (int i = 0; i < samples + 1; i++) { |
+ double sample = sin(i * interval); |
+ sin_buffer[i] = sample; |
+ cos_buffer[samples - i] = sample * interval; |
+ } |
+ |
+ // Fill this to catch out of bound accesses when calculating Math.sin(pi/2). |
+ sin_buffer[samples + 1] = sin(pi_half + interval); |
+ cos_buffer[samples + 1] = cos(pi_half + interval) * interval; |
+ |
+ return isolate->heap()->undefined_value(); |
+} |
+ |
+ |
RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) { |
SealHandleScope shs(isolate); |
ASSERT(args.length() == 2); |