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

Side by Side Diff: src/builtins.cc

Issue 2026643003: [json] replace remaining json.js code with C++ builtins. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix error message Created 4 years, 6 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
« no previous file with comments | « src/builtins.h ('k') | src/js/json.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "src/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api-arguments.h" 7 #include "src/api-arguments.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
11 #include "src/bootstrapper.h" 11 #include "src/bootstrapper.h"
12 #include "src/code-factory.h" 12 #include "src/code-factory.h"
13 #include "src/code-stub-assembler.h" 13 #include "src/code-stub-assembler.h"
14 #include "src/dateparser-inl.h" 14 #include "src/dateparser-inl.h"
15 #include "src/elements.h" 15 #include "src/elements.h"
16 #include "src/frames-inl.h" 16 #include "src/frames-inl.h"
17 #include "src/gdb-jit.h" 17 #include "src/gdb-jit.h"
18 #include "src/ic/handler-compiler.h" 18 #include "src/ic/handler-compiler.h"
19 #include "src/ic/ic.h" 19 #include "src/ic/ic.h"
20 #include "src/isolate-inl.h" 20 #include "src/isolate-inl.h"
21 #include "src/json-parser.h"
21 #include "src/json-stringifier.h" 22 #include "src/json-stringifier.h"
22 #include "src/messages.h" 23 #include "src/messages.h"
23 #include "src/profiler/cpu-profiler.h" 24 #include "src/profiler/cpu-profiler.h"
24 #include "src/property-descriptor.h" 25 #include "src/property-descriptor.h"
25 #include "src/prototype.h" 26 #include "src/prototype.h"
26 #include "src/string-builder.h" 27 #include "src/string-builder.h"
27 #include "src/uri.h" 28 #include "src/uri.h"
28 #include "src/vm-state-inl.h" 29 #include "src/vm-state-inl.h"
29 30
30 namespace v8 { 31 namespace v8 {
(...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 Handle<JSFunction> function; 2214 Handle<JSFunction> function;
2214 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 2215 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
2215 isolate, function, 2216 isolate, function,
2216 CompileString(handle(target->native_context(), isolate), 2217 CompileString(handle(target->native_context(), isolate),
2217 Handle<String>::cast(x), NO_PARSE_RESTRICTION)); 2218 Handle<String>::cast(x), NO_PARSE_RESTRICTION));
2218 RETURN_RESULT_OR_FAILURE( 2219 RETURN_RESULT_OR_FAILURE(
2219 isolate, 2220 isolate,
2220 Execution::Call(isolate, function, target_global_proxy, 0, nullptr)); 2221 Execution::Call(isolate, function, target_global_proxy, 0, nullptr));
2221 } 2222 }
2222 2223
2224 // ES6 section 24.3.1 JSON.parse.
2225 BUILTIN(JsonParse) {
2226 HandleScope scope(isolate);
2227 Handle<Object> source = args.atOrUndefined(isolate, 1);
2228 Handle<Object> reviver = args.atOrUndefined(isolate, 2);
2229 Handle<String> string;
2230 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string,
2231 Object::ToString(isolate, source));
2232 RETURN_RESULT_OR_FAILURE(
2233 isolate, string->IsSeqOneByteString()
2234 ? JsonParser<true>::Parse(isolate, string, reviver)
2235 : JsonParser<false>::Parse(isolate, string, reviver));
2236 }
2237
2223 // ES6 section 24.3.2 JSON.stringify. 2238 // ES6 section 24.3.2 JSON.stringify.
2224 BUILTIN(JsonStringify) { 2239 BUILTIN(JsonStringify) {
2225 HandleScope scope(isolate); 2240 HandleScope scope(isolate);
2226 JsonStringifier stringifier(isolate); 2241 JsonStringifier stringifier(isolate);
2227 Handle<Object> object = args.atOrUndefined(isolate, 1); 2242 Handle<Object> object = args.atOrUndefined(isolate, 1);
2228 Handle<Object> replacer = args.atOrUndefined(isolate, 2); 2243 Handle<Object> replacer = args.atOrUndefined(isolate, 2);
2229 Handle<Object> indent = args.atOrUndefined(isolate, 3); 2244 Handle<Object> indent = args.atOrUndefined(isolate, 3);
2230 RETURN_RESULT_OR_FAILURE(isolate, 2245 RETURN_RESULT_OR_FAILURE(isolate,
2231 stringifier.Stringify(object, replacer, indent)); 2246 stringifier.Stringify(object, replacer, indent));
2232 } 2247 }
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after
3920 time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, days); 3935 time_within_day = isolate->date_cache()->TimeInDay(local_time_ms, days);
3921 int year, month, day; 3936 int year, month, day;
3922 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day); 3937 isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day);
3923 m = month; 3938 m = month;
3924 dt = day; 3939 dt = day;
3925 } 3940 }
3926 double time_val = MakeDate(MakeDay(y, m, dt), time_within_day); 3941 double time_val = MakeDate(MakeDay(y, m, dt), time_within_day);
3927 return SetLocalDateValue(date, time_val); 3942 return SetLocalDateValue(date, time_val);
3928 } 3943 }
3929 3944
3945 // ES6 section 20.3.4.37 Date.prototype.toJSON ( key )
3946 BUILTIN(DatePrototypeToJson) {
3947 HandleScope scope(isolate);
3948 Handle<Object> receiver = args.atOrUndefined(isolate, 0);
3949 Handle<JSReceiver> receiver_obj;
3950 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver_obj,
3951 Object::ToObject(isolate, receiver));
3952 Handle<Object> primitive;
3953 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
3954 isolate, primitive,
3955 Object::ToPrimitive(receiver_obj, ToPrimitiveHint::kNumber));
3956 if (primitive->IsNumber() && !std::isfinite(primitive->Number())) {
3957 return isolate->heap()->null_value();
3958 } else {
3959 Handle<String> name =
3960 isolate->factory()->NewStringFromAsciiChecked("toISOString");
3961 Handle<Object> function;
3962 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, function,
3963 Object::GetProperty(receiver_obj, name));
3964 if (!function->IsCallable()) {
3965 THROW_NEW_ERROR_RETURN_FAILURE(
3966 isolate, NewTypeError(MessageTemplate::kCalledNonCallable, name));
3967 }
3968 RETURN_RESULT_OR_FAILURE(
3969 isolate, Execution::Call(isolate, function, receiver_obj, 0, NULL));
3970 }
3971 }
3930 3972
3931 // static 3973 // static
3932 void Builtins::Generate_DatePrototypeGetDate(MacroAssembler* masm) { 3974 void Builtins::Generate_DatePrototypeGetDate(MacroAssembler* masm) {
3933 Generate_DatePrototype_GetField(masm, JSDate::kDay); 3975 Generate_DatePrototype_GetField(masm, JSDate::kDay);
3934 } 3976 }
3935 3977
3936 3978
3937 // static 3979 // static
3938 void Builtins::Generate_DatePrototypeGetDay(MacroAssembler* masm) { 3980 void Builtins::Generate_DatePrototypeGetDay(MacroAssembler* masm) {
3939 Generate_DatePrototype_GetField(masm, JSDate::kWeekday); 3981 Generate_DatePrototype_GetField(masm, JSDate::kWeekday);
(...skipping 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after
5605 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) 5647 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T)
5606 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 5648 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
5607 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 5649 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
5608 #undef DEFINE_BUILTIN_ACCESSOR_C 5650 #undef DEFINE_BUILTIN_ACCESSOR_C
5609 #undef DEFINE_BUILTIN_ACCESSOR_A 5651 #undef DEFINE_BUILTIN_ACCESSOR_A
5610 #undef DEFINE_BUILTIN_ACCESSOR_T 5652 #undef DEFINE_BUILTIN_ACCESSOR_T
5611 #undef DEFINE_BUILTIN_ACCESSOR_H 5653 #undef DEFINE_BUILTIN_ACCESSOR_H
5612 5654
5613 } // namespace internal 5655 } // namespace internal
5614 } // namespace v8 5656 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/js/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698