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

Unified Diff: src/factory.cc

Issue 7344013: Expose APIs for detecting boxed primitives, native errors and Math. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
« src/api.cc ('K') | « src/factory.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index 9ba48ee5024fa1cb3a59c85864ff88604e8339b0..e48e4b5e31f7116990d80d78f7e0b51d31904130 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -242,6 +242,50 @@ Handle<String> Factory::NewExternalStringFromTwoByte(
}
+static Handle<JSValue> AllocateJSValue(Isolate* isolate,
+ JSFunction* constructor) {
+ CALL_HEAP_FUNCTION(
+ isolate,
+ isolate->heap()->AllocateJSObject(constructor),
Vyacheslav Egorov (Chromium) 2011/07/12 20:38:12 constructor will be "dead variable" if GC happens.
zarko 2011/07/12 21:42:06 Done.
+ JSValue);
+}
+
+
+static Handle<Object> CreateJSValue(Isolate* isolate,
+ JSFunction* constructor,
+ Handle<Object> value) {
+ Handle<JSValue> raw_value = AllocateJSValue(isolate, constructor);
+ if (!raw_value.is_null()) {
+ raw_value->set_value(*value);
+ }
+ return raw_value;
+}
+
+
+Handle<Object> Factory::NewBoxedString(Handle<String> value) {
+ return CreateJSValue(isolate(),
+ isolate()->global_context()->string_function(),
+ value);
+}
+
+
+Handle<Object> Factory::NewBoxedBoolean(bool value) {
+ Handle<Object> boolean(value ? isolate()->heap()->true_value()
+ : isolate()->heap()->false_value());
+ return CreateJSValue(isolate(),
+ isolate()->global_context()->boolean_function(),
+ boolean);
+}
+
+
+Handle<Object> Factory::NewBoxedNumber(double value) {
+ Handle<Object> number = NewNumber(value);
+ return CreateJSValue(isolate(),
+ isolate()->global_context()->number_function(),
+ number);
+}
+
+
Handle<Context> Factory::NewGlobalContext() {
CALL_HEAP_FUNCTION(
isolate(),
« src/api.cc ('K') | « src/factory.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698