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

Side by Side Diff: src/factory.cc

Issue 2915793002: [api] Prototype WeakRef implementation
Patch Set: Created 3 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/factory.h ('k') | src/flag-definitions.h » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/factory.h" 5 #include "src/factory.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/allocation-site-scopes.h" 8 #include "src/allocation-site-scopes.h"
9 #include "src/ast/ast.h" 9 #include "src/ast/ast.h"
10 #include "src/base/bits.h" 10 #include "src/base/bits.h"
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 DCHECK(!map->is_prototype_map()); 925 DCHECK(!map->is_prototype_map());
926 Handle<JSObject> promise_obj = NewJSObjectFromMap(map); 926 Handle<JSObject> promise_obj = NewJSObjectFromMap(map);
927 Handle<JSPromise> promise = Handle<JSPromise>::cast(promise_obj); 927 Handle<JSPromise> promise = Handle<JSPromise>::cast(promise_obj);
928 promise->set_status(v8::Promise::kPending); 928 promise->set_status(v8::Promise::kPending);
929 promise->set_flags(0); 929 promise->set_flags(0);
930 930
931 isolate()->RunPromiseHook(PromiseHookType::kInit, promise, undefined_value()); 931 isolate()->RunPromiseHook(PromiseHookType::kInit, promise, undefined_value());
932 return promise; 932 return promise;
933 } 933 }
934 934
935 void Factory::InitJSWeakRef(
936 Handle<JSWeakRef> weak_ref,
937 Handle<JSObject> target,
938 Handle<JSFunction> executor,
939 Handle<Object> holdings
940 ) {
941 Handle<JSFunction> constructor(
942 isolate()->native_context()->js_weak_ref_fun(), isolate());
943 DCHECK(constructor->has_initial_map());
944 Handle<Map> map(constructor->initial_map(), isolate());
945
946 DCHECK(!map->is_prototype_map());
947
948 weak_ref->set_target(*NewWeakCell(target));
949 weak_ref->set_executor(*executor);
950 weak_ref->set_holdings(*holdings);
951 weak_ref->set_held(false);
952 weak_ref->set_queued(false);
953
954 Handle<FixedArray> refs(isolate()->heap()->weak_refs(), isolate());
955 int num_refs = refs->length();
956 refs = isolate()->factory()->CopyFixedArrayAndGrow(refs, 1);
957 isolate()->heap()->set_weak_refs(*refs);
958 refs->set(num_refs, *weak_ref);
959 }
960
935 Handle<Context> Factory::NewNativeContext() { 961 Handle<Context> Factory::NewNativeContext() {
936 Handle<FixedArray> array = 962 Handle<FixedArray> array =
937 NewFixedArray(Context::NATIVE_CONTEXT_SLOTS, TENURED); 963 NewFixedArray(Context::NATIVE_CONTEXT_SLOTS, TENURED);
938 array->set_map_no_write_barrier(*native_context_map()); 964 array->set_map_no_write_barrier(*native_context_map());
939 Handle<Context> context = Handle<Context>::cast(array); 965 Handle<Context> context = Handle<Context>::cast(array);
940 context->set_native_context(*context); 966 context->set_native_context(*context);
941 context->set_errors_thrown(Smi::kZero); 967 context->set_errors_thrown(Smi::kZero);
942 context->set_math_random_index(Smi::kZero); 968 context->set_math_random_index(Smi::kZero);
943 Handle<WeakCell> weak_cell = NewWeakCell(context); 969 Handle<WeakCell> weak_cell = NewWeakCell(context);
944 context->set_self_weak_cell(*weak_cell); 970 context->set_self_weak_cell(*weak_cell);
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 Handle<AccessorInfo> prototype = 2960 Handle<AccessorInfo> prototype =
2935 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); 2961 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs);
2936 Descriptor d = Descriptor::AccessorConstant( 2962 Descriptor d = Descriptor::AccessorConstant(
2937 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); 2963 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs);
2938 map->AppendDescriptor(&d); 2964 map->AppendDescriptor(&d);
2939 } 2965 }
2940 } 2966 }
2941 2967
2942 } // namespace internal 2968 } // namespace internal
2943 } // namespace v8 2969 } // namespace v8
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698