Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: src/d8.cc

Issue 2433273002: [wasm] Avoid double-serializing the wire bytes (Closed)
Patch Set: externalize/internalize buffer Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <errno.h> 5 #include <errno.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 .ToLocalChecked(), 1386 .ToLocalChecked(),
1387 FunctionTemplate::New(isolate, Write)); 1387 FunctionTemplate::New(isolate, Write));
1388 global_template->Set( 1388 global_template->Set(
1389 String::NewFromUtf8(isolate, "read", NewStringType::kNormal) 1389 String::NewFromUtf8(isolate, "read", NewStringType::kNormal)
1390 .ToLocalChecked(), 1390 .ToLocalChecked(),
1391 FunctionTemplate::New(isolate, Read)); 1391 FunctionTemplate::New(isolate, Read));
1392 global_template->Set( 1392 global_template->Set(
1393 String::NewFromUtf8(isolate, "readbuffer", NewStringType::kNormal) 1393 String::NewFromUtf8(isolate, "readbuffer", NewStringType::kNormal)
1394 .ToLocalChecked(), 1394 .ToLocalChecked(),
1395 FunctionTemplate::New(isolate, ReadBuffer)); 1395 FunctionTemplate::New(isolate, ReadBuffer));
1396 Local<FunctionTemplate> experimental =
1397 FunctionTemplate::New(isolate, ExperimentalDoubleAdder);
1398 experimental->Set(isolate, "native_variant",
1399 External::New(isolate, reinterpret_cast<void*>(
1400 ExperimentalNativeDoubleAdder)));
1401 global_template->Set(String::NewFromUtf8(isolate, "experimentalDoubleAdder",
1402 NewStringType::kNormal)
1403 .ToLocalChecked(),
1404 experimental);
1396 global_template->Set( 1405 global_template->Set(
1397 String::NewFromUtf8(isolate, "readline", NewStringType::kNormal) 1406 String::NewFromUtf8(isolate, "readline", NewStringType::kNormal)
1398 .ToLocalChecked(), 1407 .ToLocalChecked(),
1399 FunctionTemplate::New(isolate, ReadLine)); 1408 FunctionTemplate::New(isolate, ReadLine));
1400 global_template->Set( 1409 global_template->Set(
1401 String::NewFromUtf8(isolate, "load", NewStringType::kNormal) 1410 String::NewFromUtf8(isolate, "load", NewStringType::kNormal)
1402 .ToLocalChecked(), 1411 .ToLocalChecked(),
1403 FunctionTemplate::New(isolate, Load)); 1412 FunctionTemplate::New(isolate, Load));
1404 // Some Emscripten-generated code tries to call 'quit', which in turn would 1413 // Some Emscripten-generated code tries to call 'quit', which in turn would
1405 // call C's exit(). This would lead to memory leaks, because there is no way 1414 // call C's exit(). This would lead to memory leaks, because there is no way
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 Local<v8::ArrayBuffer> buffer = ArrayBuffer::New(isolate, data->data, length); 1727 Local<v8::ArrayBuffer> buffer = ArrayBuffer::New(isolate, data->data, length);
1719 data->handle.Reset(isolate, buffer); 1728 data->handle.Reset(isolate, buffer);
1720 data->handle.SetWeak(data, ReadBufferWeakCallback, 1729 data->handle.SetWeak(data, ReadBufferWeakCallback,
1721 v8::WeakCallbackType::kParameter); 1730 v8::WeakCallbackType::kParameter);
1722 data->handle.MarkIndependent(); 1731 data->handle.MarkIndependent();
1723 isolate->AdjustAmountOfExternalAllocatedMemory(length); 1732 isolate->AdjustAmountOfExternalAllocatedMemory(length);
1724 1733
1725 args.GetReturnValue().Set(buffer); 1734 args.GetReturnValue().Set(buffer);
1726 } 1735 }
1727 1736
1737 void Shell::ExperimentalDoubleAdder(
1738 const v8::FunctionCallbackInfo<v8::Value>& args) {
1739 DCHECK(sizeof(char) == sizeof(uint8_t)); // NOLINT
1740 Local<Number> a = Local<Number>::Cast(args[0]);
1741 Local<Number> b = Local<Number>::Cast(args[1]);
1742 Local<Number> ret = Number::New(args.GetIsolate(), a->Value() + b->Value());
1743 args.GetReturnValue().Set(ret);
1744 }
1745
1746 double Shell::ExperimentalNativeDoubleAdder(double a, double b) {
1747 return a + b;
1748 }
1728 1749
1729 // Reads a file into a v8 string. 1750 // Reads a file into a v8 string.
1730 Local<String> Shell::ReadFile(Isolate* isolate, const char* name) { 1751 Local<String> Shell::ReadFile(Isolate* isolate, const char* name) {
1731 int size = 0; 1752 int size = 0;
1732 char* chars = ReadChars(isolate, name, &size); 1753 char* chars = ReadChars(isolate, name, &size);
1733 if (chars == NULL) return Local<String>(); 1754 if (chars == NULL) return Local<String>();
1734 Local<String> result = 1755 Local<String> result =
1735 String::NewFromUtf8(isolate, chars, NewStringType::kNormal, size) 1756 String::NewFromUtf8(isolate, chars, NewStringType::kNormal, size)
1736 .ToLocalChecked(); 1757 .ToLocalChecked();
1737 delete[] chars; 1758 delete[] chars;
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 } 2835 }
2815 2836
2816 } // namespace v8 2837 } // namespace v8
2817 2838
2818 2839
2819 #ifndef GOOGLE3 2840 #ifndef GOOGLE3
2820 int main(int argc, char* argv[]) { 2841 int main(int argc, char* argv[]) {
2821 return v8::Shell::Main(argc, argv); 2842 return v8::Shell::Main(argc, argv);
2822 } 2843 }
2823 #endif 2844 #endif
OLDNEW
« no previous file with comments | « src/d8.h ('k') | src/runtime/runtime.h » ('j') | src/runtime/runtime-test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698